m***@lycos.com
2009-03-15 08:55:43 UTC
Hi,
I am a beginner at STL and I am having a lot of trouble understanding
function adaptors. My team lead has given me the following cheat
sheet:
(1) If f = bind1st(g,x)
then f(y) means g(x,y)
(2) If f = bind2nd(g,x)
then f(y) means g(y,x)
(3) If f = mem_fun(mf)
then f(p) means p->mf()
(4) If f = mem_fun_ref(mf)
then f(r) means r.mf()
(5) If f = not1(g)
then f(x) means !g(x)
(6) If f = not2(g)
then f(x,y) means !g(x,y)
The problem is that in most of the examples of say bind2nd that I am
seeing, there is no "y" being passed [as in f(y) means g(y,x) in the
TL's cheat sheet].
Here's an example usage:
find_if(v.begin(), v.end(), bind2nd(greater<int>(), 5))
In this case:
- "greater<int>()" is the same as "g" in the cheat sheet
- 5 is x in the cheat sheet
But where is y (from the cheat sheet) being passed?
Thanks for your help!
Masood
I am a beginner at STL and I am having a lot of trouble understanding
function adaptors. My team lead has given me the following cheat
sheet:
(1) If f = bind1st(g,x)
then f(y) means g(x,y)
(2) If f = bind2nd(g,x)
then f(y) means g(y,x)
(3) If f = mem_fun(mf)
then f(p) means p->mf()
(4) If f = mem_fun_ref(mf)
then f(r) means r.mf()
(5) If f = not1(g)
then f(x) means !g(x)
(6) If f = not2(g)
then f(x,y) means !g(x,y)
The problem is that in most of the examples of say bind2nd that I am
seeing, there is no "y" being passed [as in f(y) means g(y,x) in the
TL's cheat sheet].
Here's an example usage:
find_if(v.begin(), v.end(), bind2nd(greater<int>(), 5))
In this case:
- "greater<int>()" is the same as "g" in the cheat sheet
- 5 is x in the cheat sheet
But where is y (from the cheat sheet) being passed?
Thanks for your help!
Masood