Boost logo

Boost Users :

From: Hughes, James (jhughes_at_[hidden])
Date: 2007-06-11 09:26:20


> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Peter Dimov
> Sent: 11 June 2007 14:11
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] [bind] Help with
> functionalcompositionofshared_ptr::use_count in std::map
>
> Hughes, James wrote:
>
> > RemoveIf(Fred.begin(),
> > Fred.end(),
> > boost::bind(&map<string, shared_ptr<data>
> > >::value_type::second::unique, _1)
> > )
> >
> > Still get same compile fault however.
>
> It would be nice if this could work with a single bind, but
> unfortunately you need two:
>
> boost::bind( &shared_ptr<data>::unique,
> boost::bind( &map<string, shared_ptr<data>
> >::value_type::second, _1 )
> )
>
> There is an additional pitfall here; depending on the version
> of boost::bind and the compiler, the inner bind may return a
> shared_ptr by value, making the use_count at least 2. You
> should probably just fall back to the old-fashioned
>
> bool second_unique( map<string, shared_ptr<data> >::value_type & v ) {
> return v.second.unique();
> }
>
> (I'm using a non-const reference as a parameter to guard
> against potential silent implicit conversions which could
> also increase the use_count.)
>
> Removing the unique entries sounds like purging a cache,
> maybe weak_ptr will work better in your map?
>
>

Thanks Peter - you are right - it's a cache!

James

This message (including any attachments) contains confidential
and/or proprietary information intended only for the addressee.
Any unauthorized disclosure, copying, distribution or reliance on
the contents of this information is strictly prohibited and may
constitute a violation of law. If you are not the intended
recipient, please notify the sender immediately by responding to
this e-mail, and delete the message from your system. If you
have any questions about this e-mail please notify the sender
immediately.


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