Structs by ref in D2
Daniel Keep
daniel.keep.lists at gmail.com
Fri Aug 21 08:51:12 PDT 2009
Steven Schveighoffer wrote:
> ...
>
> The issue is possibly with ref. There are two reasons to use ref, 1 is
> to be able to change the data referenced, 2 is for passing speed.
>
> 1 is bad for rvalues. 2 should be ok for rvalues.
>
> If there was a way to signify you only want to use ref for reason 2,
> there would be a good solution. Most of the time, that's const ref, but
> what you really want is head-const ref, which isn't currently possible.
> If a struct has references to other values, they might be lvalues, and
> you may want to be able to change them.
>
> I'm uncertain as to how often you would want to pass an rvalue as a ref
> that had lvalue reference in it, but at the very least, ref const should
> be valid.
>
> -Steve
In my own code, I usually record my intent by using "inout" for
variables I intend to modify and "ref" for ones which I don't.
Always seemed reasonable to me.
More information about the Digitalmars-d-learn
mailing list