auto ref

Leandro Lucarella llucax at gmail.com
Thu Dec 17 08:26:52 PST 2009


Simen kjaeraas, el 17 de diciembre a las 02:16 me escribiste:
> On Wed, 16 Dec 2009 12:00:46 +0100, KennyTM~ <kennytm at gmail.com> 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

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
We are born naked, wet and hungry
Then things get worse



More information about the Digitalmars-d mailing list