Am 08.05.2014 13:05, schrieb monarch_dodra:
On Thursday, 8 May 2014 at 07:09:24 UTC, Sönke Ludwig wrote:
Just a general note: This is not only interesting for range/slice
types, but for any user defined reference type (e.g. RefCounted!T or
Isolated!T).

Not necessarily: As soon as indirections come into play, you are
basically screwed, since const is "turtles all the way down".

So for example, the conversion from "const RefCounted!T" to
"RefCounted!(const T)" is simply not possible, because it strips the
const-ness of the ref count.

What we would *really* need here is NOT:
"const RefCounted!T" => "RefCounted!(const T)"
But rather
"RefCounted!T" => "RefCounted!(const T)"

The idea is to cut out the "head const" directly. This also applies to
most ranges too BTW.

We'd be much better of if we never used `const MyRange!T` to begin with,
but simply had a conversion from `MyRange!T` to `MyRange!(const T)`,
which references the same data.

In fact, I'm wondering if this might not be a more interesting direction
to explore.

The reference count _must_ be handled separate from the payload's const-ness, or a const(RefCount!T) would be completely dysfunctional. Also, if you take the other example, Isolated!T, there is no reference count involved and const(Isolated!T) <-> Isolated!(const(T)) would be exactly what is needed.

Reply via email to