Boost logo

Boost :

From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2005-12-20 16:51:09


Eric Niebler wrote:
> Thorsten Ottosen wrote:
>
>>Eric Niebler wrote:
>>
>>
>>>I noticed this too, and decided it was a bug in gcc. I think that given
>>>
>>> template<typename T> struct conv {
>>> operator T() { return T(); }
>>> };
>>> template<typename T> void bar(T&) {}
>>>
>>>the expression:
>>>
>>> typedef foo const cfoo;
>>> bar(true ? conv<foo>() : cfoo());
>>>
>>>should compile,
>>
>>
>>Even though bar takes a T& and not const T& parameter?
>
>
>
> Yes. The type of (true ? conv<foo>() : cfoo()) is "rvalue of foo const."
> And const rvalues successfully bind to T&, with T deduced as "foo const."

well, if you call bar(1), it won't compile. what makes this different?

I'm also confused by the fact that the above conversion operator can add
a const to T, that is to say, T is specified as foo, not const foo, and
so the generated class would look like

struct conv_foo
{
   operator foo() { return foo(); }
};

I just don't get it :-(

-Thorsten


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