How does the c++ standard define the recognition of manipulators or just manipulators in general?
For example:
using namespace std;
ostream& hello_manip(ostream& os){
os<<"Hello there, fine fellow!"; return os;
}
int main(){
cout<<hello_manip;
}
The code cout << hello_manip would seem to be translated into operator<<( cout, hello_manip ) or cout.operator<<(hello_manip), but instead it takes up the form of hello_manip( cout ).
There’s an overload of
operator<<that accepts a function pointer and invokes it. No magic involved.Processing of simple manipulators such as yours is described in section 27.7.3.6.3 of the Standard.
More complex manipulators (which accept parameters and carry state) are implemented by returning functor objects, which have their own
operator<<overloads.