DIP 1016 and const ref parameters

XavierAP n3minis-git at yahoo.es
Wed Jun 19 12:33:44 UTC 2019


I often use a pattern of having const ref struct parameters (as 
in C++) but this doesn't work in the case of rvalues. The 
workaround of defining an overload that calls its own name is 
terrible. I understand there was a DIP 1016 by Manu asking for 
this case to work. As far as I can tell, this was rejected, but 
later reconsidered, and now Andrei is starting up a new one[1]? 
Apologies but I'm not sure where these discussions are 
centralized. But if anyone has any idea or guess how seriously 
and in what kind of time this could be expected, that would be my 
first side question.

My main learning question is whether the const ref parameter 
pattern is good in D? In C++ I see it everywhere, but are there 
better alternatives, in particular in D, or is there no point 
because some copy elision optimization may be guaranteed? In 
short am I right in writing const ref parameters, or am I doing 
something silly (and as important as this DIP may otherwise be, 
it wouldn't affect me as much as I think)??

As far as I can see, this DIP would be helpful for two use cases: 
const ref, and return ref with method chains. Are there others?
__________
[1] 
https://forum.dlang.org/post/d90a7424-a986-66f1-e889-a9abd55e0e65@erdani.org


More information about the Digitalmars-d-learn mailing list