View source code
Display the source code in std/conv.d from which this page was generated on
github.
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.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.conv.unsigned
Returns the corresponding unsigned value for (e.g. if x has type
xint, it returns cast(uint) ). The advantage compared xto the cast
is that you do not need to rewrite the cast if later changes type
(e.g from xint to long).
Note that the result is always mutable even if the original type was const
or immutable. In order to retain the constness, use std.traits.Unsigned.
Prototype
auto unsigned(T)( T x ) if (isIntegral!T);
Example
immutable int s = 42; auto u1 = unsigned(s); //not qualified static assert(is(typeof(u1) == uint)); Unsigned!(typeof(s)) u2 = unsigned(s); //same qualification static assert(is(typeof(u2) == immutable uint)); immutable u3 = unsigned(s); //explicitly qualified
Authors
Walter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara