4 ms·
There's probably far more reasonable cases of temporaries being immediately destructed than you'd expect. One that springs to mind is gtest. It defines a bunch
by jmgao 9y ago
There's probably far more reasonable cases of temporaries being immediately destructed than you'd expect.
One that springs to mind is gtest. It defines a bunch of macros like ASSERT_TRUE that return a temporary object that has operator<< overloads to let you add additional information to the assertion failure. For example:
ASSERT_NE(-1, open("/foo", O_RDONLY)) << "failed to open file: " << strerror(errno);
It's perfectly legitimate to just go ASSERT_TRUE(1 != 2), though.
- wfunction 9y agoLike I said: > That's definitely not "immediately destroyed", there's operator<< being called between construction and destruction.
- yorwba 9y agoThe point is that you have the option of using operator<<, but if you don't exercise that option, the temporary object is destroyed immediately.