my_macro << 1 << "hello world" << blah->getValue() << std::endl;
should expand into:
std::ostringstream oss;
oss << 1 << "hello world" << blah->getValue() << std::endl;
ThreadSafeLogging(oss.str());
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A temporary of type
my_streamis created, which is a subclass ofostringstream. All operations to that temporary work as they would on anostringstream.When the statement ends (ie. right after the semicolon on the whole printing operation in main()), the temporary object goes out of scope and is destroyed. The
my_streamdestructor callsThreadSafeLoggingwith the data “collected” previously.Tested (g++).
Thanks/credits to dingo for pointing out how to simplify the whole thing, so I don’t need the overloaded
operator<<. Too bad upvotes can’t be shared.