c++ - How does QDebug() << stuff; add a newline automatically? -
I'm trying to implement my own QDebug () style debug-output stream, it's basically What I've done so far:
Structure Debug {#if Defined (Debug) Template & lt; Typename T & gt; Std :: ostream & amp; Operator & lt; & Lt; (T const & amp; A) const {std :: cout & lt; & Lt; a; Return std :: cout; } #template & lt; Typename T & gt; Debug Cons & amp; Operator & lt; & Lt; (T const & amp;) const {return * this; } / * Should be handled separately from manipulators (endless): * Manipulator functions which are a stream & amp; As a logic and a * stream & amp; * / Debug constant & amp; Operator & lt; & Lt; (Std :: ostream & amp; (* manip) (std :: ostream & amp ;;)) const {// nothing with the machine returns *; } #end if };
Specific Uses:
debug () & lt; & Lt; "Accessories" & lt; & Lt; "More stuff" & lt; & Lt; Std :: endl;
But I do not want to add std :: endl,
My question is basically how can I tell when the operator of the return type & lt; & Lt; Not being used by another operator & lt; & Lt; (And therefore attach to the end)?
The only way I can think of achieving anything like this is to create a list of print items associated with each temporary object created by debug (), then print everything, together In ~ Debug (), I print a new line (and I can do clever things like putting spaces), but obviously this is not ideal because I am not guaranteed that the floating object The extent of being destroyed to the end (or I?).
QT uses a method similar to "Avon" for details of the implementation, but they all Some stream in one of the underlying text streams, and then stream over the destruction of temporary QDebug objects returned by QDebug () and flush an end line.
Comments
Post a Comment