Boost logo

Boost Users :

From: Jan Ohlenburg (jan.ohlenburg_at_[hidden])
Date: 2006-08-09 08:38:37


Hi,
thanks for your reply. I was not using boost:bind since I thought it must be
bound to a pointer. The following line does the trick for me:

boost::bind( &Object::setFieldImpl<T>, _1, fieldId, fieldData );

Regards,
Jan

----------------------------------------------------------------------
Dipl.-Inform. Jan Ohlenburg
Fraunhofer Institut fuer Angewandte Informationstechnik FIT
Forschungsgruppe Collaborative Virtual and Augmented Environments
Schloss Birlinghoven
D - 53754 Sankt Augustin, Germany
Telefon: +49-2241-14-2724
e-Fax: +49-2241-14-4-2724
Telefax: +49-2241-14-2084
e-mail: mailto:jan.ohlenburg_at_[hidden]
 

> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of Peter Dimov
> Sent: Wednesday, August 09, 2006 2:27 PM
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] Question about boost::bind2nd
>
> Jan Ohlenburg wrote:
> > Hi everybody,
> > I would like to bind a member function within the template function
> > using the template argument. Please have a look at the following code:
> >
> > template<typename T> void Object::setField(FieldId fieldId, const T&
> > fieldData)
> > {
> > // call for_each with setFieldImpl ...
> > shadowCopies->for_each ( boost::bind2nd(
> > boost::mem_fun(&Object::setFieldImpl<T>), fieldId, fieldData)));
> > }
> >
> > template<typename T> void Object::setFieldImpl(FieldId fieldId, const
> > T& fieldData)
> > {
> > ... do some stuff...
> > }
>
> bind2nd is soo last century... have you tried using boost::bind?
>
> boost::bind( &Object::setFieldImpl<T>, fieldId, fieldData )
>
> It is not guaranteed to work (MSVC 6 in particular might not be able to
> handle it), but it stands a better chance.
>
> If that fails, you'd probably need to use
>
> void (Object::*pmf)(FieldId, const T&) = &Object::setFieldImpl;
>
> ... boost::bind( pmf, fieldId, fieldData ) ...
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net