Qt has a nice debugging feature called so
qDebug() << first_qobject << second_qobject;
it creates a line with some "standard string" of objects and - and whatβs the important part - prints \n and blows off steam after second_object . I want to reproduce this behavior by convention that all my classes have a std::string to_string() method, which I call:
struct myDebug{ template<typename T> myDebug& operator<<(T t){ std::cout << t.to_string() << " "; // space-separated return *this; } }; struct Point{ std::string to_string(){ return "42"; } }; myDebug() << Point() << Point(); // should produce "42 42" plus a newline (which it doesn't)
Now my question is: is there a way to find out that after returning *this second time, the returned object is no longer called? So that I can print std::endl ? qDebug() seems to be able to do this.
source share