Possible Duplicate:
C++ Using stringstream after << as parameter
I’ve a function like this
print(const std::string& message);
How can I wrap it at some other place, such that I can use, say
print2("some message"<<object);
this should internally call the above function.
Here’s a C++11 solution using variadic templates:
Usage:
An interface with a variable number of arguments is neater and more direct than an awkward use of shift operators in the function call, since the latter requires you to create a stream object explicitly, and you’d then need to deal with the stream’s low-level
rdbufdirectly, and that approach wouldn’t have the original, no-argument version as a special case.