Boost logo

Boost Users :

From: bjorn.karlsson_at_[hidden]
Date: 2002-04-30 06:17:53


> From: sashan [mailto:sashang_at_[hidden]]
[snip]
> Is there a better way that doesn't involve 1) having to write
> a wrapper class around a basic type (or any type) and 2)
> doesn't involve changing the shared_ptr::operator==.
>

As others have pointed out, the solution is to use a function object and
std::find_if. In this case, the comparison doesn't even need a separate
predicate - the (exceptionally cool) Boost.Bind library can be used instead:

vector<shared_ptr<int> >::iterator
it=std::find_if(vec.begin(),vec.end(),bind(std::equal_to<int>(),bind(&shared
_ptr<int>::operator*, _1),42));

Bjorn Karlsson

[Non-text portions of this message have been removed]


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