The line
os << std::hex;
ends up calling the overload
basic_ostream<charT,traits>& basic_ostream::operator<<(basic_ostream<charT,traits>& (*pf)(basic_ostream<charT,traits>&))
which is an operator<<()
overload that takes a pointer to a function with a basic_ostream<>
argument. That's that std::hex
is here.
That operator<<()
overload just calls the function through the pointer. So you can do any of the following which are equivalent:
os << &std::hex; // makes the function pointer explicit using the & operator
std::hex(os); // call the `std::hex` function using a normal function call syntax
// or directly call the function that `std::hex(os)` is specified to do:
os.setf(std::ios_base::hex, std::ios_base::basefield);
It's too bad that MISRA complains about the idiomatic way of setting an output stream to hex formatting.