|
Boost Users : |
Subject: [Boost-users] using bind with find_if
From: Dennis Jones (djones_at_[hidden])
Date: 2011-03-09 14:23:24
Hello,
I am currently using find_if with bind2nd to perform a search on a vector.
My current code looks like this:
struct OverrideMatches : public std::binary_function<const TItemOverride,
const TItemOverride, bool>
{
bool operator()( const TItemOverride& OverrideSource, TItemOverride
OverrideTarget ) const
{
return OverrideSource.ChildAssyItemRecNo ==
OverrideTarget.ChildAssyItemRecNo &&
OverrideSource.LinkItemRecNo == OverrideTarget.LinkItemRecNo;
}
};
TItemOverrideGateway::Container_t::iterator where =
std::find_if( FOverridesContainer.begin(),
FOverridesContainer.end(),
std::bind2nd( OverrideMatches(),
TItemOverride( "", 0, "", 0, ChildItemRecNo,
LinkItemRecNo ) ) );
I would like to eliminate the need for that temporary object to hold the
values I am searching for (and just specify the values instead), and to do
that, I want to try using boost::bind instead of std::bind2nd, but I have
not been able to determing exactly what that syntax would look like. I know
I will need placeholders for the values to search on (ChildItemRecNo,
LinkItemRecNo), but then how does the element from the vector get passed to
the
I think I want the functor to look something like this:
struct OverrideMatches
{
bool operator()( const TItemOverride &OverrideSource,
const RecNo_t ChildItemRecNo,
const RecNo_t LinkItemRecNo )
{
return OverrideSource.ChildAssyItemRecNo == ChildItemRecNo &&
OverrideSource.LinkItemRecNo == LinkItemRecNo;
}
};
If the above functor is correct (and maybe it's not, in which case, please
correct me), how do I then rewrite std::find_if to use it with boost::bind?
Thank you very much,
Dennis Jones
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