On Thu, 17 Dec 2009 17:26:52 +0100, Leandro Lucarella <[email protected]>
wrote:
Simen kjaeraas, el 17 de diciembre a las 02:16 me escribiste:
On Wed, 16 Dec 2009 12:00:46 +0100, KennyTM~ <[email protected]> wrote:
>On Dec 16, 09 15:18, Walter Bright wrote:
>>There's a need in generic code to have a function take a parameter by
>>ref if it is an lvalue, and by value if it is an rvalue. This can be
>>addressed by making it a template using auto ref:
>>
>>T foo(T)(auto ref T x) { ... }
>>
>>foo(3) // call by value
>>int y;
>>foo(y) // call by reference
>>
>>There is also a need to 'transmit' the ref'ness to the return value.
>>This can be done with auto ref:
>>
>>auto ref foo(T)(auto ref T x) { return x; }
>>
>>foo(3) => int foo(int x)
>>foo(y) => ref int foo(ref int x)
>>
>>This means that the generic forwarding function would look like:
>>
>>auto ref foo(alias F, T...)(auto ref T args) { return F(args); }
>
>auto const?
auto const auto ref Foo bar( auto const auto ref Foo arg ) {
return arg;
}
Am I the only one who finds this confusing?
Just call "auto const auto ref" "auto auto":
auto auto Foo bar( auto auto Foo arg ) {
return arg;
}
=P
Even better, with return type inference:
auto auto auto bar( T )( auto auto T arg ) {
return arg;
}
:p
--
Simen