Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Just like thrift objects implement a custom toString in Java, there should be an inline friend function that writes a text representation of the struct to a std::ostream. Probably makes sense for the text representation to be similar to C++:
class MyThriftClass { friend std::ostream& operator<<(std::ostream& o, MyThriftClass) { o << "MyThriftClass["; o << "field1=" << field1; if (__isset.field2) { o << ", field2=" << field2; } o << ", list1=" << apache::thrift::util::to_string(list1); return o << "]"; } // ... }
There will also probably be a util.h file to include that implements generic template to_string for lists, maps, & sets.
Attachments
Issue Links
- breaks
-
THRIFT-3336 Thrift generated streaming operators added in 0.9.2 cannot be overridden
- Closed
- is related to
-
THRIFT-2691 C++ - new operator<< could be used in tutorial
- Closed