lundi 25 juin 2018

std::ostream manipulators overloads

Below is how ostream deals with manipulators such as std::endl

ostream& ostream::operator << ( ostream& (*op)(ostream&)) {
// call the function passed as parameter with this stream as the argument
   return (*op)(*this);
}

My question is why the parameter is defined as a pointer to a function and not as std::function ?

std::function can store any callable method (function, lambda, function object, etc). Wouldn't that be more powerful? Is there an overload for that ?

The above is an example from the book The C++ standard library a tutorial and reference - Josuttis).

Aucun commentaire:

Enregistrer un commentaire