All my classes implement a dump member function, e.g.:
struct A {
template
std::basic_ostream &
template
auto operator<< (std::basic_ostream & str, const T & t) -> decltype(t.dump(str))
{
static_assert(std::is_same
&>::value,
".dump(ostream&) does not return ostream& !");
return t.dump(str);
}
This overloads operator<< only for types that define an appropriate dump member.
Edit: added static_assert for better messages.