|
Boost Users : |
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-06-27 04:52:36
Peter,
thanks for you answer. I anderstand this all and agree with you. But I still think, that a hint,
note etc. in the documentation could be useful. Most of the boost docs are in form of tutorials
and are not just dry specifications for some interfaces and their concepts. That's why I think
this kind of note, hint whatever could be useful.
With Kind Regards,
Ovanes Markarian
On Mon, June 26, 2006 19:56, Peter Dimov wrote:
> Ovanes Markarian wrote:
>
>> Sorry,
>>
>> you are right. I forgot that all operators are overloaded or defined
>> in std namespace.
>
> It's a bit more subtle than that. As a general rule, an operator needs to be
> defined in the namespace of the class for which it applies. If you had
>
> std::ostream& operator<<( std::ostream& os, my::X const & x );
>
> you'd need to put this operator in namespace my, because that's where the
> class my::X resides.
>
> All this assumes that your compiler supports argument-dependent lookup
> (ADL); for older compilers, the rule is "put the operator wherever it
> appears to work."
>
> However, since the operator you are defining:
>
> template <typename T>
> std::ostream& operator<<( std::ostream& os, const std::vector<T>& v );
>
> applies to std::vector, it needs to be defined in namespace std.
>
> In principle, a class N::X is supposed to also define the necessary support
> operators in namespace N, but std::vector doesn't do that (mainly because it
> isn't clear how is this operator supposed to work; there are many legitimate
> ways to output a sequence.)
>
> This is a general C++ problem, not specific to Boost.Variant, so it's
> understandable why the documentation doesn't mention it.
>
>
>
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