[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost-users
Subject:    Re: [Boost-users] boost::function - why does this work??
From:       "Peter Dimov" <pdimov () mmltd ! net>
Date:       2003-11-27 16:49:31
Message-ID: 011001c3b506$6f786be0$1d00a8c0 () pdimov2
[Download RAW message or body]

Matt S Trentini wrote:

[...]

> And I was able to do this:
>
>      Extract(listOfHcs.begin(), listOfHcs.end(), needToFill,
> &HandleClass::handle);
>
> And it worked like a charm.  needToFill gets filled and I was happy.
> :)
>
> However we also had containers of _pointers_to_ HandleClasses.  So in
> some cases our vector looked like:
>
>      std::vector<HandleClass *> listOfHcs;
>
> Yet the same code worked!  I couldn't, and can't, for the life of me
> understand what was going on (I expected that I would have to wrap the
> (*it) in a boost::remove_pointer which worried me because my compiler
> - MSVC7.0 - doesn't support partial template specialization).  Don't
> get me wrong, I'm happy that it work but can anyone explain what
> fandangelory is going on inside boost::function (or perhaps it's some
> C++ magic?) to allow this?

When you construct a boost::function from &HandleClass::handle, what
actually gets stored is boost::mem_fn(&HandleClass::handle). See

    http://www.boost.org/libs/mem_fn/

Even

     std::vector< boost::shared_ptr<HandleClass> > listOfHcs;

will work.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic