Originally posted by curious2007
[code=cpp]
Average<double> obj;
doube avg = obj(3.0, 4.0); //functor: obj used as a function
[/code]
The STL binary_function is a base class for creating adaptable functors. You might read up on these. STL algorithms use adaptable functors heavily.
In STL-speak, an binary function is a function (or functor) that takes two arguments of type T and returns a type T.
A binary function that returns a bool is called a binary predicate.
Do not confuse binary function (a concept) with binary_function (a class).
Any STL code that calls for a binary function can use an object of your Average class.
Since there already is a binary_function in the std namespace, you should put your binary_function in your own namespace. Otherwise, you will get bit.
Assume you include your binary_function (all goes well) but if your don't and you also happen to use the <functional> header your code will use the std::binary_fun ction. Now you can't tell which binary_function the compiler grabbed.
Since you can't know the names of the members of a namespace, you have to put your stuff in your own namespace in the assumption that you can keep track of yourself.
Comment