bind2nd question

I

Ioannis Vranos

Shouldn't this compile?


#include <vector>
#include <algorithm>
#include <functional>


int main()
{
using namespace std;

vector<int> vec(1000, 10);


vector<int>::iterator p= find( vec.begin(), vec.end(),
bind2nd(less<int>(), 11) );
}
 
K

Kurt Stutsman

Ioannis said:
Shouldn't this compile?


#include <vector>
#include <algorithm>
#include <functional>


int main()
{
using namespace std;

vector<int> vec(1000, 10);


vector<int>::iterator p= find( vec.begin(), vec.end(),
bind2nd(less<int>(), 11) );
}
You want to use std::find_if() instead of std::find(). The third paramater to std::find() is
expected to be the value you're looking for, where as std::find_if()'s third paramater is a binary
predicate.
 
K

Kurt Stutsman

Kurt said:
You want to use std::find_if() instead of std::find(). The third
paramater to std::find() is expected to be the value you're looking for,
where as std::find_if()'s third paramater is a binary predicate.
Make that a Unary Predicate not a Binary Predicate. Sorry.
 
J

Jerry Coffin

Ioannis said:
Shouldn't this compile?
No.

vector<int>::iterator p= find( vec.begin(), vec.end(),
bind2nd(less<int>(), 11) );

std::find looks for a particular value. To use a predicate, you want to
call std::find_if.
 

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

Similar Threads

count_if bind2nd greater<string> = error??? 4
Overloading operator== for pair<> 2
bind2nd 1
compiler errors on iterator 2
on std::bind2nd 3
Compiler Error C2676 12
Crossword 2
bind2nd question 2

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top