|
Boost : |
Subject: Re: [boost] [proto] Problems with operator <<
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-08-25 04:08:47
> Folks,
>
> I'm having no end of problems with operator<< and proto.
>
> In the beginning, operator << was overloaded for stream output and
> everything worked OK, then I added the left shift operator<< to the list
> of protoized operators in the grammar and everything broke. The strange
> thing is that:
>
> std::cout << a+b;
>
> correctly finds my stream out overload:
>
> template <class Exp>
> inline std::ostream& operator << (std::ostream& os, const
> big_number_exp<Exp>& r)
>
> But
>
> std::cout << a;
>
> no longer calls:
>
> template <class Backend>
> inline std::ostream& operator << (std::ostream& os, const
> big_number<Backend>& r)
>
> But calls the proto << operator instead.
>
> I'm at a complete loss to explain this, both of my overloads are in the
> same namespace as their respective types, and as far as I can see both
> should be preferred to the proto versions.
To answer my own question - in case anyone else gets bitten by this - the
answer is you need to provide overloads with both const and non-const
reference RHS arguments to effectively hide the proto operator versions.
Still some hair left yours.... John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk