From slices to perfect imitators: opByValue

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Thu May 8 00:01:42 PDT 2014


On Thu, 08 May 2014 06:48:57 +0000
bearophile via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> Currently only the slices decay in mutables, while an immutable
> int doesn't become mutable:

That's because what's happening is that the slice operator for arrays is
defined to return a tail-const slice of the array, and then any time you slice
it - be it explicit or implicit - you get a tail-const slice. It really has
nothing to do with passing an argument to a function beyond the fact that that
triggers an implicit call to the slice operator.  For feature parity here,
what we really should be looking it is how to make opSlice have feature
parity, not adding a new function. And ints can't be sliced, so there is no
situation where you end up with a tail-const slice of an int.

- Jonathan M Davis


More information about the Digitalmars-d mailing list