I'm working on a C++ wrapper library for some API. Suppose I've implemented some struct or class type Foo. I can't make up my mind whether or not to provide an ostream& operator<<(ostream& os, const Foo& x) with my library.
On one hand:
- It's convenient for debugging.
- It doesn't interfere with the rest of the code.
- I don't expect
Foos to be printed except when debugging, so this shouldn't clash with users wanting to serializeFoos to files or similar activities.
On the other hand:
- It's not necessary, i.e. the wrappers' functionality does not require it for anything.
- Library users might want to some other debug-printing format, different than what I write. Or maybe they use Antony Polukhin's dark voodoo automatic struct printing (magic_get).
- Unless carefully separated from the rest of the code, it forces the library user to include
<iostreams>, which is not a trivial thing.
Am ignoring some other primal consideration for any of the options? Or, to put it different: What would be an appropriate criterion for including such operators with the library?
Additional info:
- All of
Foos members can be obtained by the user, so they don't need a member or a friend function to achieve the same effect.