View source code
							
							
						
								Display the source code in std/conv.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.
							
						Module std.conv
A one-stop shop for converting values from one type to another.
| Category | Functions | 
|---|---|
| Generic | asOriginalTypecastFromemplaceparsetotoChars | 
| Strings | textwtextdtexthexString | 
| Numeric | octalroundTosignedunsigned | 
| Exceptions | ConvExceptionConvOverflowException | 
Functions
| Name | Description | 
|---|---|
| 
									asOriginalType(value)
								 | Returns the representation of an enumerated value, i.e. the value converted to the base type of the enumeration. | 
| 
									dtext(args)
								 | Convenience functions for converting one or more arguments of any type into text (the three character widths). | 
| 
									emplace(chunk)
								 | Given a pointer chunkto uninitialized memory (but already typed
asT), constructs an object of non-classtypeTat that
address. IfTis a class, initializes the class reference to null. | 
| 
									emplace(chunk, args)
								 | Given a pointer chunkto uninitialized memory (but already typed
as a non-class typeT), constructs an object of typeTat
that address from argumentsargs. IfTis a class, initializes
the class reference toargs[0]. | 
| 
									emplace(chunk, args)
								 | Given a raw memory area chunk(but already typed as a class typeT),
constructs an object ofclasstypeTat that address. The constructor
is passed the argumentsArgs. | 
| 
									emplace(chunk, args)
								 | Given a raw memory area chunk, constructs an object ofclasstypeTat
that address. The constructor is passed the argumentsArgs. | 
| 
									emplace(chunk, args)
								 | Given a raw memory area chunk, constructs an object of non-classtypeTat that address. The constructor is passed the
argumentsargs, if any. | 
| 
									parse(source)
								 | The parsefamily of functions works quite like thetofamily, except that:
 | 
| 
									parse(s)
								 | Parses a character input range to an integral value. | 
| 
									parse(s)
								 | Takes a string representing an enumtype and returns that type. | 
| 
									parse(source)
								 | Parses a character range to a floating point number. | 
| 
									parse(s)
								 | Parsing one character off a range returns the first element and calls popFront. | 
| 
									parse(s)
								 | Parsing a character range to typeof(null)returnsnullif the range
spells"null". This function is case insensitive. | 
| 
									parse(s, lbracket, rbracket, comma)
								 | Parses an array from a string given the left bracket (default  '['), right bracket (default']'), and element separator (by
 default','). A trailing separator is allowed. | 
| 
									parse(s, lbracket, rbracket, keyval, comma)
								 | Parses an associative array from a string given the left bracket (default  '['), right bracket (default']'), key-value separator (default ':'), and element seprator (by default','). | 
| 
									signed(x)
								 | Returns the corresponding signed value for x(e.g. ifxhas typeuint, it returnscast(int) x). The advantage compared to the cast
    is that you do not need to rewrite the cast ifxlater changes type
    (e.g fromuinttoulong). | 
| 
									text(args)
								 | Convenience functions for converting one or more arguments of any type into text (the three character widths). | 
| 
									toChars(value)
								 | Convert integer to a range of characters. Intended to be lightweight and fast. | 
| 
									unsigned(x)
								 | Returns the corresponding unsigned value for x(e.g. ifxhas typeint, it returnscast(uint) x). The advantage compared to the cast
    is that you do not need to rewrite the cast ifxlater changes type
    (e.g frominttolong). | 
| 
									wtext(args)
								 | Convenience functions for converting one or more arguments of any type into text (the three character widths). | 
Classes
| Name | Description | 
|---|---|
| 
									ConvException
								 | Thrown on conversion errors. | 
| 
									ConvOverflowException
								 | Thrown on conversion overflow errors. | 
Templates
| Name | Description | 
|---|---|
| 
									castFrom
								 | A wrapper on top of the built-in cast operator that allows one to restrict casting of the original type of the value. | 
| 
									roundTo
								 | Rounded conversion from floating point to integral. | 
| 
									to
								 | The totemplate converts a value from one type to another.
The source type is deduced and the target type must be specified, for example the
expressionto!int(42.0)converts the number 42 fromdoubletoint. The conversion is "safe", i.e.,
it checks for overflow;to!int(4.2e10)would throw theConvOverflowExceptionexception. Overflow checks are only
inserted when necessary, e.g.,to!double(42)does not do
any checking because anyintfits in adouble. | 
Manifest constants
| Name | Type | Description | 
|---|---|---|
| hexString | Converts a hex literal to a string at compile time. | |
| octal | The octalfacility provides a means to declare a number in base 8.
Usingoctal!177oroctal!"177"for 127 represented in octal
(same as 0177 in C). | 
Authors
Walter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.