468,720 Members | 1,689 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

bind2nd question

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) );
}


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #1
4 2352
Ioannis Vranos wrote:
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.
Jul 23 '05 #2
Kurt Stutsman wrote:
Ioannis Vranos wrote:
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.

Make that a Unary Predicate not a Binary Predicate. Sorry.
Jul 23 '05 #3
You are using a predicate, you need to use find_if rather than find.

--
Imanpreet Singh Arora

Jul 23 '05 #4
Ioannis Vranos wrote:
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.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by red floyd | last post: by
3 posts views Thread by John Black | last post: by
3 posts views Thread by ES Kim | last post: by
2 posts views Thread by flyaflya | last post: by
4 posts views Thread by dzikus | last post: by
1 post views Thread by PS | last post: by
8 posts views Thread by Noah Roberts | last post: by
2 posts views Thread by benben | last post: by
3 posts views Thread by Bruintje Beer | last post: by
4 posts views Thread by responsible | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.