CopyConstness

Returns the type of ToType with the "constness" of FromType. A type's constness refers to whether it is const, immutable, or inout. If FromType has no constness, the returned type will be the same as ToType.

template CopyConstness (
FromType
ToType
) {}

Examples

1 const(int) i;
2 CopyConstness!(typeof(i), float) f;
3 assert( is(typeof(f) == const float));
4 
5 CopyConstness!(char, uint) u;
6 assert( is(typeof(u) == uint));
7 
8 //The 'shared' qualifier will not be copied
9 assert(!is(CopyConstness!(shared bool, int) == shared int));
10 
11 //But the constness will be
12 assert( is(CopyConstness!(shared const real, double) == const double));
13 
14 //Careful, const(int)[] is a mutable array of const(int)
15 alias MutT = CopyConstness!(const(int)[], int);
16 assert(!is(MutT == const(int)));
17 
18 //Okay, const(int[]) applies to array and contained ints
19 alias CstT = CopyConstness!(const(int[]), int);
20 assert( is(CstT == const(int)));

Meta

Suggestion Box / Bug Report