improvement request - enabling by-value-containers

Jonathan Schmidt-Dominé devel at the-user.org
Wed Dec 15 01:16:31 PST 2010


> Sorry, ref const scope for such containers and PODs etc., const scope for
> primitives and references. Of course, that is exactly what you want to
> have for function-paramaters, temporary variables temporarily holding a
> read-only container-element, like foreach-variables etc. That would not
> influence the value-semantics.

Maybe you want to say that this is waste because containers often have only 
one or two elements, pointer and length, “d”-pointer, etc. Well, I think 
there should be a possibility to tell D that passing a container as const 
ref does not require the extra-level of indirection. Same could be possible 
for non-const-references and for swapping. swap(x, y) would simply check how 
to swap x and y in a nice way (I think swap(x, y) is always better than tmp 
= x; x = y; y =x;). That would make it optimal against extra-indirection and 
unneccessary copying. However, even with normal references it would not 
require more indirection than by-reference types.


More information about the Digitalmars-d mailing list