Does D really need something like const&?
Namespace
rswhite4 at googlemail.com
Fri Mar 1 13:16:46 PST 2013
Currently small structs are moved as rvalues and copied as
lvalues and that seems like the most performant way.
But for massy structs this doesn't make sense, if you must pass
them to functions as parameter, without declaring the parameter
as 'ref'.
Why? Because in general this is very unperformant and that is
mostly not what you want.
So I thougth like many other still do: something is missing here,
we need something like const&.
But: why do we need something like that?
The more important question is: why is our massy struct a struct
and not a class?
Does it make sense that it isn't a class? If we could answer this
question generally with No or if we don't have any important
reason why the massy struct should stay a struct and not a class,
then we do not need something like const&.
If your data is massy: use a class. If not and you don't need
polymorphism: use a struct. Done! ... or not?
We should ask us:
1. How could we answer the questions above?
2. Do we really need something that takes both, rvalues and
lvalues, if it isn't a template?
I'm really interested to hear what is your opinion.
More information about the Digitalmars-d
mailing list