Reputation: 132310
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:
Foo
s to be printed except when debugging, so this shouldn't clash with users wanting to serialize Foo
s to files or similar activities.On the other hand:
<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:
Foo
s members can be obtained by the user, so they don't need a member or a friend function to achieve the same effect.Upvotes: 5
Views: 151