Hi Bill,
On Tue, Feb 14, 2012 at 11:26 AM, Bill Buklis wrote:
struct data
{
int a;
int b;
};
// function object that takes two data parameters - contents unimportant for
the example
struct match_data;
std::vector<data> data_range;
data search_value;
boost::find_if( data_range, boost::bind(match_data(), _1, search_value) );
Interesting question. How about:
boost::begin(data_range | filtered(boost::bind(match_data(), _1,
search_value))); ?
HTH,
Nate
P.S. Had to compile it to prove it to myself: (cygwin g++ 4.5.3, old
boost trunk)
$ cat simple.cpp
#include
#include
#include
#define BOOST_TYPEOF_SILENT
#include
#include <iostream>
#include <vector>
using boost::adaptors::filtered;
struct data
{ int a;
int b;
};
struct match_data
{
typedef bool result_type;
bool operator()(const data& lhs, const data& rhs)
{ return lhs.a == rhs.a; }
};
int main()
{
std::vector<data> data_range;
data search_value;
#if 0
data data1; data1.a = 3;
data data2; data1.a = 5;
data_range.push_back(data1);
data_range.push_back(data2);
search_value.a = 5;
#endif
BOOST_AUTO(it, boost::begin(data_range | filtered(
boost::bind(match_data(), _1, search_value))).base());
if(it != data_range.end())
std::cout << "Found: " << it->a;
else
std::cout << "Not found.";
}