Boost logo

Boost :

Subject: Re: [boost] [proto] Problems with operator <<
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-08-25 11:57:53


>> 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.
>
> Why answer you own question when I answered it for you yesterday?
>
> http://article.gmane.org/gmane.comp.lib.boost.devel/222816

Strange... that was exactly the answer I needed but it didn't show up in my
inbox... would have saved me some time too :-(

> And I think you have a reason to actual disable proto's operators
> instead of just hide them. Check the msg I sent yesterday.

The thing is I need left and right shift to be protoized, but I also need to
be able to overload for stream out, I ended up with several overloads
looking like:

template <class Stream, class Backend>
typename enable_if<is_convertible<Stream*, std::ostream*>,
std::ostream&>::type operator << (Stream& os, big_number<Backend>& r)

Which did the trick, and preserve protos shift operators, while still
working with all stream types.

BTW I do specify a proto grammar, and only enable the operators I need on a
case by case basis, in this case though I would need to restrict the grammar
so that proto's shift operators are only enabled for RHS arguments of
integer type. Is that possible?

John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk