Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2008-04-07 14:30:38


"Peter Dimov" <pdimov_at_[hidden]> writes:

> Anthony Williams:
>> "Peter Dimov" <pdimov_at_[hidden]> writes:
>>
>>> Anthony Williams:
>>>> "Peter Dimov" <pdimov_at_[hidden]> writes:
>>>>
>>>>> Eric Niebler:
>>>>>
>>>>>> Can you write what the identity function object would look like in
>>>>>> C++0x?
>>>>>
>>>>> struct identity
>>>>> {
>>>>> template<class A> A operator()( A && a ) const
>>>>> {
>>>>> return std::forward<A>( a );
>>>>> }
>>>>> };
>>>>>
>>>>> I guess.
>>>>
>>>> No. That will convert lvalues to rvalues.
>>>
>>> Try it.
>>
>> I have, and it doesn't work.
>
> With what compiler does it not work? Can you post the example program?

It's a pre-release compiler. I can't tell you which one as I'm under an NDA.

>> Besides, you can see in the signature: it returns "A" by value.
>
> There's a special deduction rule for A&&, where A is a template parameter:
> when passed an lvalue of type T, A is deduced as T& and not as T. So in this
> case operator() returns a T& "by value".

I see that in 14.8.2.1p3. I'd not really intaken that before. Thanks.

However, in this case I'm surely missing something else. Andrei's talk on
Friday went on for a few slides about why the function above is insufficient,
how you needed three overloads (A&&, A& and A const&), and with a sample
implementation from Howard Hinnant that used a traits class to deduce the
correct return value with only one overload.

Anthony

-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

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