Any functor type should consistent with container type. Pay attention to the
second example, you just input Foo to binary_function template, no const
and &.
Make predicates pure function, see effective STL item 39. That means that
there is no side effect in side the fucntion. 1) no I/O, 2) no change any state.
More effective STL item 42. Make sure less<T> means operator< . Don’t
specialization of std::less. If you need to another compare, just define your
own compare function.
Generator no argument, unary functions with one argument and binary
function with two arguments
A long story,part 1 , begin from a program, a function can be declare with
parameter name.
part2, when you call a function, you can pass a non-name temporary
arguments. here, you don’t need give a name of parameter, the const
reference will prolong the temporary argument life until the end of
function, You have to use const, because you can’t change a temporary
arguments.
part4, Now let see this example. I want to build a list obj, name is data. But
compiler think that I declare a function, name is data, take two arguments,
and return a list<int>.