|
Boost Users : |
From: Andy Stevenson (andy.stevenson_at_[hidden])
Date: 2008-04-07 18:56:28
Ovanes,
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.
Andy
_____
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Ovanes Markarian
Sent: 07 April 2008 22:43
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [boost][lexical_cast] simple example doesn't
workwith vector<T>
Yes, that's true...
the std operator << is defined as:
template<class CharT, class Traits>
basic_ostream<CharT, Traits>& operator<<(basic_ostream<CharT, Traits>,
some_overloaded_type const&);
due some_overaloaded_type is not a template argument, the template can not
be specialized on it, and therefore it is illegal to overload this operator.
Andy, to your other post:
standard only says that this is undefined behavior to overload std functions
if it works with your compiler it does not mean it will always work and that
it will not break existing code or cause some sleepless night to another
developer why some other operator << then the std one is called.
This is just a reminder, that not everything that compiles is automatically
standard conform.
Best Regards,
Ovanes
On 4/7/08, Steven Watanabe <watanabesj_at_[hidden]> wrote:
AMDG
Ovanes Markarian wrote:
> Just an addition:
>
> Explicit specialization of std templates is legal. So if you _exactly_
> know vector types for which your <<-operator should work you can write:
>
> namespace std
> {
> template<>
> ostream& operator<< (ostream& os, const vector<MyTypeX>& v)
> {
> copy(v.begin(), v.end(), ostream_iterator<T>(os, ";"));
> return os;
> }
> }
>
> By the way there was a big discussion about this on std list and I
> fluently read the upcoming Standard draft and saw that this paragraph
> changed. I not any longer sure if this will be allowed with the new
> standard.
There has to be template to specialize. The std library doesn't have
an overload of operator<< that matches std vector. Specialization
can't change that.
In Christ,
Steven Watanabe
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
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