unsigned

Returns the corresponding unsigned value for x (e.g. if x has type int, it returns cast(uint) x). The advantage compared to the cast is that you do not need to rewrite the cast if x later changes type (e.g from int 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.

  1. auto unsigned(T x)
  2. auto unsigned(T x)
    unsigned
    (
    T
    )
    (
    T x
    )

Examples

import std.traits : Unsigned;
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

Meta