About ref used for performance reasons with struct
Namespace
rswhite4 at googlemail.com
Mon Feb 11 15:43:08 PST 2013
How about this approach:
You almost need functions, which takes structs as an rvalue, for
things like:
----
struct A { }
void foo(A a) { }
foo(A());
----
So what's about something like this (Yes I mark it with '&'):
----
struct A { }
void foo(A& a) { }
----
The compiler decides at compile time whether A should be taken by
ref or by value.
So for example, if A.sizeof > 16, it changes to:
----
void foo(ref A a) {
----
otherwise:
----
void foo(A a) {
----
In the latter case nothing happens for calls like: foo(A());
But in the former case the call:
foo(A());
is changed to:
auto __temp = A(); foo(__temp);
More information about the Digitalmars-d
mailing list