
On Mon, Apr 7, 2008 at 6:56 PM, Andy Stevenson
Thanks for this. I get the idea about 'just because it compiles doesn't mean it is std conformant'. I guess the thread has me curious about the extensibility of the ostream<< or the lexical_cast for that matter that depends on ostream<< extensibility being. I feel I must be missing something here that the std authors had in mind.
The problem here is that you're trying to, effectively, add something to the standard library, which isn't really allowed. Nothing in ostream &operator<<(ostream &, std::vector<T>) is "yours" (a type you defined), so it's non-trivial, which isn't considered a problem since most often you aren't doing that (and it's still possible without too much trouble when you are). As Steven Watanabe pointed out, as soon as you're writing an operator<< for your own type, you simply define it in the same "place" (meaning namespace) as the type itself and everything will "just work" (thanks to ADL).