2

boost::bind handles boost::shared_ptr the same way as raw pointers.

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

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

I would love to have a boost::bind that handles QPointers as raw pointers pointer.

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" );

Is there anyone who has made the specialization for QPointer?

If not do you know where to start or what needs to be specialized, so I can do it myself.

demonplus
  • 5,613
  • 12
  • 49
  • 68
TimW
  • 8,351
  • 1
  • 29
  • 33
  • What version of Qt are you using? The documented QPointer class in version 4.5 doesn't have a get method. From the looks of it your desired syntax should work... – Judge Maygarden Jun 11 '09 at 13:47
  • Sorry get is for lambda/shared_ptr, for QPointer it is data – TimW Jun 11 '09 at 14:07
  • Template Argument Deduction means that QPointer arguments have their type deduced as QPointer, even if they have an operator T*() const. – MSalters Jun 11 '09 at 14:16

1 Answers1

5

Adding this overload of the get_pointer function should do the trick:

namespace boost {
    template<typename T> T * get_pointer(QPointer<T> const& p)
    {
        return p;
    }
}
Judge Maygarden
  • 26,961
  • 9
  • 82
  • 99
  • This is not a specialization, it's an overload, which has slightly different resolution rules. Important to remember if you mix both (which you shouldn't, really). See Herb Sutter: http://www.gotw.ca/publications/mill17.htm – Alex B Jul 13 '11 at 04:17