Boost logo

Boost :

Subject: Re: [boost] Search a vector of tuples?
From: Robert Dailey (rcdailey.lists_at_[hidden])
Date: 2012-04-23 18:30:19


On Thu, Apr 12, 2012 at 6:13 AM, Mathias Gaunard <
mathias.gaunard_at_[hidden]> wrote:

> On 12/04/12 10:36, Robert Jones wrote:
>>
>> *** 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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk