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
{
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