From slices to perfect imitators: opByValue

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Thu May 8 18:09:23 PDT 2014


On Thu, 08 May 2014 17:18:03 +0200
Sönke Ludwig via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> > Right, which is my point: "const(RefCount!T)" *is* dysfunctional,
> > which is why you'd want to skip it out entirely in the first
> > place.This holds true for types implemented with RefCount, such as
> > Array and Array.Range.
>
> Okay, I didn't know that. For various reasons (mostly weak ref
> support) I'm using my own RefCount template, which casts away
> const-ness of the reference counter internally.

Which technically violates the type system and isn't something that should be
done - though you _should_ be able to get away with it as long as immutable
isn't involved. Still, the compiler is permitted to assume that const objects
aren't mutated (because that's what const is supposed to guarantee), so you're
risking subtle bugs due to compiler optimizations and whatnot.

- Jonathan M Davis


More information about the Digitalmars-d mailing list