[Issue 5325] Mutable references to const/immutable/shared classes

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Oct 10 08:19:56 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=5325

--- Comment #7 from Michel Fortin <michel.fortin at michelf.com> ---
(In reply to Martin Nowak from comment #6)
> True, for array elements you cannot specify a storage class.
> 
> const(Object)[] ary;  // ary of tail const objects or array of const objects
> const(Object[]) cary; // const array of const objects

A storage class will also not work for templates. For instance:

Container!(const(Object)) c; // container of const references to const objects
Container!(const(Object)ref) c; // container of mutable references to const
objects

A storage class will not work with the various facilities to manage qualifiers:

Unqual!(const(Object)) // should give you const(Object)ref

A storage class will not work with pointers (similar case to array):

const(Object)ref object;
auto ptr = &object; // type is const(Object)ref*
*ptr = new Object; // works!

Putting this in a storage class will work in a handful of cases (those you can
already solve with Rebindable), but it does not play well with anything written
to be generic.

--


More information about the Digitalmars-d-bugs mailing list