|
Boost : |
Subject: Re: [boost] Search a vector of tuples?
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2012-04-12 05:09:38
On 04/12/2012 10:36 AM, Robert Jones wrote:
> On Wed, Apr 11, 2012 at 11:33 PM, Robert Dailey<rcdailey.lists_at_[hidden]>wrote:
>
>> Is there a method in the boost library to iterate a vector of boost::tuple
>> objects, comparing the 1st element in the tuple of each tuple to a value
>> that I specify? My tuple is setup like so:
>>
>> typedef boost::tuple<int, int, char const*> Tuple;
>> typedef std::vector<Tuple> ErrorStringMap;
>>
>> ErrorStringMap mystrings = tuple_list_of
>> (10, "10", "ten")
>> (20, "20", "twenty")
>> (30, "30", "thirty")
>> (10, "10", "ten");
>>
>> I want to search the vector of tuples and do something with every tuple
>> that has the number 10 as the first element in the tuple.
>>
>>
> *** 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 );
The Phoenix solution would look like the following:
#include<boost/range.hpp>
#include<boost/range/adaptors/filtered.hpp>
// ... and maybe some other range headers
#include<boost/phoenix.hpp>
#include<boost/fusion/adapted/tuple.hpp>
for_each( mystrings | boost::adaptors::filtered( boost::phoenix::at_c<0>(_1)
== 10 ), yourAction );
or:
for_each( mystrings, if_(boost::phoenix::at_c<0>(_1) == 10)[yourAction]);
>
> Just off the top of my head, no idea if that will really work.
>
> HTH
>
> - Rob.
>
> _______________________________________________
> Unsubscribe& other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk