fork download
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4.  
  5. class Log {
  6. public:
  7. Log() = default;
  8. Log(const Log&) = delete;
  9.  
  10. ~Log() {
  11. cout << this << " dtor" << endl;
  12. cout << stream_.str() << endl;
  13. }
  14.  
  15. template <class T>
  16. Log& operator<<(const T& info) {
  17. cout << this << " <<" << endl;
  18. stream_ << info;
  19. return *this;
  20. }
  21.  
  22. private:
  23. stringstream stream_;
  24. };
  25.  
  26. int main() {
  27. []() -> Log&& {
  28. Log log;
  29. log << "A";
  30. return move(log);
  31. } () << "B";
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
0xbfe84064 <<
0xbfe84064 dtor
A
0xbfe84064 <<