$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] Search a vector of tuples?
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-04-23 18:59:53
> >> *** Not Tested or Compiled ***
> >>
> >> #include<boost/range.hpp>
> >> #include<boost/range/adaptors/**filtered.hpp>
> >> // ... and maybe some other range headers
> >> #include<boost/bind.hpp>
> >>
> >> for_each( mystrings | boost::adaptors::filtered( boost::bind( get<0>, _1 )
> >> == 10 ), yourAction );
> >>
> >
> > You probably can't take the address of get<0>.
> >
> > Also, you could remove the dependence on filtered by using find_if instead
> > of for_each.
>
> How would I use find_if() for this? I tried this:
>
> using namespace boost::phoenix;
> using namespace boost::phoenix::arg_names;
> using namespace boost::range;
>
> ErrorStringMap::const_iterator it =
> find_if( g_error_info, at_c<0>(_1) == error_code );
>
> if( it != g_error_info.end() ) {
> return *it;
> }
>
> However I haven't used Boost.Range before and I don't see any documentation
> in Boost.Range about the binary-or operator being used with the algorithms.
> My above code won't compile, apparently find_if() won't take an actor as a
> predicate. No idea how to convert it though.
find_if() can take an actor as a predicate. You have a different problem.
My guess would be that you need to include <boost/fusion/adapted/boost_tuple.hpp>
in order for Fusion (which is used by phoenix's at_c) to recognize Boost.Tuple.
If that doesn't fix the problem, please post a complete example that fails
to compile for us to be able to help you further.
Regards,
Nate