View source code
Display the source code in std/traits.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Alias std.traits.CopyConstness
Returns the type of Target
with the "constness" of Source
. A type's constness
refers to whether it is const
, immutable
, or inout
. If source
has no constness, the
returned type will be the same as Target
.
alias CopyConstness(FromType, ToType)
= Unshared!(CopyTypeQualifiers!(FromType,ToType));
Example
const(int) i;
CopyConstness!(typeof(i), float) f;
assert( is(typeof(f) == const float));
CopyConstness!(char, uint) u;
assert( is(typeof(u) == uint));
//The 'shared' qualifier will not be copied
assert(!is(CopyConstness!(shared bool, int) == shared int));
//But the constness will be
assert( is(CopyConstness!(shared const real, double) == const double));
//Careful, const(int)[] is a mutable array of const(int)
alias MutT = CopyConstness!(const(int)[], int);
assert(!is(MutT == const(int)));
//Okay, const(int[]) applies to array and contained ints
alias CstT = CopyConstness!(const(int[]), int);
assert( is(CstT == const(int)));
Authors
Walter Bright,
Tomasz Stachowiak (isExpressions
),
Andrei Alexandrescu,
Shin Fujishiro,
Robert Clipsham,
David Nadlinger,
Kenji Hara,
Shoichi Kato
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.