Unconst

Removes the outer layer of const, inout, or immutable from type T.

If none of those qualifiers have been applied to the outer layer of type T, then the result is T.

For the built-in scalar types (that is bool, the character types, and the numeric types), they only have one layer, so const U simply becomes U.

Where the layers come in is pointers and arrays. const(U*) becomes const(U)*, and const(U[]), becomes const(U)[]. So, a pointer goes from being fully const to being a mutable pointer to const, and a dynamic array goes from being fully const to being a mutable dynamic array of const elements. And if there are multiple layers of pointers or arrays, it's just that outer layer which is affected - e.g. const(U**) would become const(U*)*.

For user-defined types, the effect is that const U becomes U, and how that affects member variables depends on the type of the member variable. If a member variable is explicitly marked with any mutability qualifiers, then it will continue to have those qualifiers even after Unconst has stripped all mutability qualifiers from the containing type. However, if a mutability qualifier was on the member variable only because the containing type had that qualifier, then when Unconst removes the qualifier from the containing type, it is removed from the member variable as well.

Also, Unconst has no effect on what a templated type is instantiated with, so if a templated type is instantiated with a template argument which has a mutability qualifier, the template instantiation will not change.

version(StdDdoc)
template Unconst (
T
) {}

Meta