Pregunta

boost::bind maneja boost::shared_ptr la misma manera que los punteros primas.

QObject * object(new QObject);
boost::shared_ptr<QObject> sharedObject(new QObject);

bind(&QObject::setObjectName, object, _1)( "name" );
bind(&QObject::setObjectName, sharedObject, _1)( "name" );

Me encantaría tener un boost::bind que maneja QPointers como puntero punteros primas.

QPointer<QObject> guardedObject(new QObject);    
// i want to write it like this
bind(&QObject::setObjectName, guardedObject, _1)( "name" );
//now i have to do it like this
bind(&QObject::setObjectName, bind(&QPointer<QObject>::data, guardedObject), _1)( "name" );

¿Hay alguien que ha hecho de la especialización para QPointer?

Si no sabes por dónde empezar o qué necesita ser especializada, por lo que puedo hacer por mí mismo.

¿Fue útil?

Solución

La adición de esta sobrecarga de la función get_pointer debe hacer el truco:

namespace boost {
    template<typename T> T * get_pointer(QPointer<T> const& p)
    {
        return p;
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top