View source code
							
							
						
								Display the source code in std/conv.d from which thispage was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create aBugzilla 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 usinglocal clone.
							
						Function std.conv.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).
						
				auto unsigned(T)(
				
  T x
				
				)
				
				if (isIntegral!T);
				
				
				auto unsigned(T)(
				
  T x
				
				)
				
				if (isSomeChar!T);
						
					
				Note that the result is always mutable even if the original type was const
    or immutable. In order to retain the constness, use Unsigned.
Example
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
Authors
Walter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara
License
					Copyright © 1999-2025 by the D Language Foundation | Page generated by ddox.