I want to declare a function which writes to std::out
by default, but also optionally enables writing to another output stream, if any is provided. For example:
print_function(std::string & str,
std::ostream & out = std::cout,
std::ostream & other = nullptr) // <-- how to make it optional???
{
out << str;
if (other == something) // if optional 'other' argument is provided
{
other << str;
}
}
Setting nullprt
obviously does not work, but how can this be done?