example program using binder1st and binder2nd needed

S

subramanian100in

I have written a program that uses the binder function templates
'bind1st' and 'bind2nd'. But I am unable to come up with a program
that directly uses binder class templates 'binder1st' and 'binder2nd'.
Kindly give a program wherein the use of the class template
'binder1st' and 'binder2nd' is unvoidable - in other words, binder1st
and binder2nd must be used.

Thanks
V.Subramanian
 
F

Francesco S. Carta

on said:
I have written a program that uses the binder function templates
'bind1st' and 'bind2nd'. But I am unable to come up with a program
that directly uses binder class templates 'binder1st' and 'binder2nd'.
Kindly give a program wherein the use of the class template
'binder1st' and 'binder2nd' is unvoidable - in other words, binder1st
and binder2nd must be used.

Those functions are just additional features in a library, and as such,
everything that can be done with them can also be done without them:
they only make it easier to accomplish some tasks.

If you're looking for something that /can/ be done with those binding
functions, then that would be a reasonable question.

If you take a look to the last post in my thread about dynamic menus
(started about one week ago) you'll see an example of something that,
for me, is /best/ done with binding functions.

My last version there uses tr1::bind, but that's just another lever of
indirection for using bind1st and bind2nd in an easier manner.
 
J

Juha Nieminen

I have written a program that uses the binder function templates
'bind1st' and 'bind2nd'. But I am unable to come up with a program
that directly uses binder class templates 'binder1st' and 'binder2nd'.
Kindly give a program wherein the use of the class template
'binder1st' and 'binder2nd' is unvoidable - in other words, binder1st
and binder2nd must be used.

Given that using std::bind1st() and std::bind2nd() are never completely
unavoidable either, then using std::binder1st and std::binder2nd cannot be
that either.

In some situation it might be convenient to store the binder object
locally if the same binder object needs to be used more than once. For
example something like:

std::binder2nd<std::less<int> > lessThan10 =
std::bind2nd(std::less<int>(), 10);

unsigned count1 = std::count_if(v1.begin(), v1.end(), lessThan10);
unsigned count2 = std::count_if(v2.begin(), v2.end(), lessThan10);

(C++0x makes it even easier by providing the new 'auto' keyword...)
 

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

No members online now.

Forum statistics

Threads
474,471
Messages
2,571,831
Members
48,802
Latest member
shadowoftheunknown
Top