boost::bind annoyance with home grown iterator

J

joe

I'm having an annoyance with a boost::bind failure that I can't figure
out. I'm using an iterator and have all the required fields for
iterator (value_type, etc).

I'm trying to call the function:

find(obj.begin(),
obj.end(),
boost::bind(std::greater<double>(), _1, 4.4);

which gives the error:
stl_algo.h:172: error: no match for 'operator==' in (&_first)-
MyIter<T>::eek:perator* [with T = double]() == __val'

I'm surprised this fails, because all the following work fine:
double a = *obj.begin();
double b = *obj.begin();

and most telling:
bool a = (*obj.begin() == 4.4);

since the code in stl_algo.h is doing exactly that. What could boost
be doing to the _1 placeholder? I assumed it did little more than use
operator* on each iterator as it is passed them.

Any ideas?
 
K

Kira Yamato

I'm having an annoyance with a boost::bind failure that I can't figure
out. I'm using an iterator and have all the required fields for
iterator (value_type, etc).

I'm trying to call the function:

find(obj.begin(),
obj.end(),
boost::bind(std::greater<double>(), _1, 4.4);

which gives the error:
stl_algo.h:172: error: no match for 'operator==' in (&_first)-
MyIter<T>::eek:perator* [with T = double]() == __val'

That's because _1 is not of type double, but rather of type

boost::lambda::placeholder1_type.

Have you tried using boost.lambda instead?

using namespace boost::lambda;

find_if(obj.begin(), obj.end(), _1 > 4.4);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,513
Latest member
JeremyLabo

Latest Threads

Top