Efficiently passing structs

bitwise via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 5 07:14:51 PDT 2015


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. Also, I don't see how someone could arrive at the above  
solution without showing up here and asking first.

>> Why not just add "rvref" to D?
>
> D is already bloated.

Some of the discussions about auto ref seem to have arrived at the idea  
that adding a keyword is the only way fix this without changing existing  
behavior or adding new behavior that would share syntax with old behavior  
and be confusing.

Anyways, for my purposes, templates will do fine, so thanks!

   Bit


More information about the Digitalmars-d-learn mailing list