Efficiently passing structs
rsw0x via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 5 07:44:13 PDT 2015
On Tuesday, 5 May 2015 at 14:14:51 UTC, bitwise wrote:
> On Tue, 05 May 2015 00:20:15 -0400, rsw0x
> <anonymous at anonymous.com> wrote:
>> it does, auto ref can bind to both lvalues and rvalues. Create
>> the function with an empty template like so,
>>
>> import std.stdio;
>>
>> struct S{
>> }
>>
>> void Foo()(auto ref S s){
>> }
>>
>> void main(){
>> S s;
>> Foo(s);
>> Foo(S());
>> }
>>
>> There might be other ways that I'm unaware of.
>
> Interesting.. Has this always worked? Theres a couple of forum
> conversations about trying to get "auto ref" to work for
> non-templates. The main problem seems to be that auto ref wont
> work for virtual functions.
I know its worked for a while, I often use it when I'm too lazy
to put attributes in and just have the templates infer them for
me ;)
> Also, I don't see how someone could arrive at the above
> solution without showing up here and asking first.
>
You're probably right, maybe someone should submit a PR to
https://github.com/p0nce/d-idioms/
More information about the Digitalmars-d-learn
mailing list