Boost logo

Boost Users :

From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2008-04-07 20:43:32


On Mon, Apr 7, 2008 at 6:56 PM, Andy Stevenson
<andy.stevenson_at_[hidden]> wrote:
> 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).


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net