1

I feel there should be a single liner with boost::phoenix that would let me stream an object having a member function ...::stream_to(std::ostream&) with << syntax. Something like this:

struct x { void stream_to(std::ostream&); }
LOG_INFO << MAGIC_SOMETHING(x);

But struggling to find that MAGIC_SOMETHING(...). Am specifically interested in a solution that won't require me doing a forwarding marker struct and ostream operator for it.

bobah
  • 18,364
  • 2
  • 37
  • 70
  • That can't be done. The problem is ADL. Your best bet is a wrapper (e.g. `stream(x)` that returns an IO manipulator to invoke `stream_to`. – sehe Nov 26 '15 at 23:12
  • (I'm assuming there is no common base class for the structs implementing `stream_to`) – sehe Nov 26 '15 at 23:14
  • @sehe - no common base class. One other example is to stream `boost::ptree::write_xml(...)` directly into the logger stream without intermediate temporaries (`write_xml` takes stream as one of arguments). – bobah Nov 26 '15 at 23:18
  • Yeah, just write a manipulator. – sehe Nov 26 '15 at 23:21

0 Answers0