
7 Apr
2008
7 Apr
'08
5:51 p.m.
Anthony Williams:
"Peter Dimov" <pdimov@pdimov.com> writes:
Anthony Williams:
"Peter Dimov" <pdimov@pdimov.com> 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?
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".