Const ref and rvalues again...
Dmitry Olshansky
dmitry.olsh at gmail.com
Thu Nov 8 10:28:39 PST 2012
11/7/2012 3:54 AM, Manu пишет:
> If the compiler started generating 2 copies of all my ref functions, I'd
> be rather unimpressed... bloat is already a problem in D. Perhaps this
> may be a handy feature, but I wouldn't call this a 'solution' to this issue.
> Also, what if the function is external (likely)... auto ref can't work
> if the function is external, an implicit temporary is required in that case.
>
What's wrong with going this route:
void blah(auto ref X stuff){
...lots of code...
}
is magically expanded to:
void blah(ref X stuff){
...that code..
}
and
void blah(X stuff){
.blah(stuff); //now here stuff is L-value so use the ref version
}
Yeah, it looks _almost_ like a template now. But unlike with a template
we can assume it's 2 overloads _always_. External fucntion issue is
then solved by treating it as exactly these 2 overloads (one trampoline,
one real). Basically it becomes one-line declaration of 2 functions.
Given that temporaries are moved anyway the speed should be fine and
there is as much bloat as you'd do by hand.
Also hopefully inliner can be counted on to do its thing in this simple
case.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list