The OpenD Programming Language

std.conv

A one-stop shop for converting values from one type to another.

Members

Classes

ConvException
class ConvException

Thrown on conversion errors.

ConvOverflowException
class ConvOverflowException

Thrown on conversion overflow errors.

Enums

LetterCase (from std.ascii)
enum LetterCase via public import std.ascii : LetterCase;

Letter case specifier.

Functions

asOriginalType
OriginalType!E asOriginalType(E value)

Returns the representation of an enumerated value, i.e. the value converted to the base type of the enumeration.

dtext
dstring dtext(T args)

Convenience functions for converting one or more arguments of any type into text (the three character widths).

emplace (from core.lifetime)
T* emplace(void[] chunk, Args args) via public import core.lifetime : emplace;

Given a raw memory area chunk, constructs an object of non-class type T at that address. The constructor is passed the arguments args, if any. Preconditions: chunk must be at least as large as T needs and should have an alignment multiple of T's alignment. Note: This function can be @trusted if the corresponding constructor of T is @safe.

parse
auto parse(Source source)

$(PANEL The `parse` family of functions works quite like the $(LREF to) family, except that: $(OL $(LI It only works with character ranges as input.) $(LI It takes the input by reference. This means that rvalues (such as string literals) are not accepted: use `to` instead.) $(LI It advances the input to the position following the conversion.) $(LI It does not throw if it could not convert the entire input.)) )

parse
auto parse(Source s)
auto parse(Source source, uint radix)

Parses an integer from a character input range.

parse
auto parse(Source s)

Parses an enum type from a string representing an enum member name.

parse
auto parse(Source source)

Parses a floating point number from a character range.

parse
auto parse(Source s)

Parses one character from a character range.

parse
auto parse(Source s)

Parses typeof(null) from a character range if the range spells "null". This function is case insensitive.

parse
auto parse(Source s, dchar lbracket, dchar rbracket, dchar 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
auto parse(Source s, dchar lbracket, dchar rbracket, dchar keyval, dchar 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
auto signed(T x)

Returns the corresponding signed value for x (e.g. if x has type uint, it returns cast(int) 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 uint to ulong).

text
string text(T args)

Convenience functions for converting one or more arguments of any type into text (the three character widths).

toChars
auto toChars(T value)

Convert integer to a range of characters. Intended to be lightweight and fast.

unsigned
auto unsigned(T x)

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).

wtext
wstring wtext(T args)

Convenience functions for converting one or more arguments of any type into text (the three character widths).

Templates

castFrom
template castFrom(From)

A wrapper on top of the built-in cast operator that allows one to restrict casting of the original type of the value.

hexString
template hexString(wstring hexData)

Converts a hex literal to a string at compile time.

hexString
template hexString(string hexData)
template hexString(dstring hexData)

Converts a hex literal to a string at compile time.

octal
template octal(string num)
template octal(alias decimalInteger)

The octal facility provides a means to declare a number in base 8. Using octal!177 or octal!"177" for 127 represented in octal (same as 0177 in C).

roundTo
template roundTo(Target)

Rounded conversion from floating point to integral.

to
template to(T)

The to template converts a value from one type to another. The source type is deduced and the target type must be specified, for example the expression to!int(42.0) converts the number 42 from double to int. The conversion is "safe", i.e., it checks for overflow; to!int(4.2e10) would throw the ConvOverflowException exception. Overflow checks are only inserted when necessary, e.g., to!double(42) does not do any checking because any int fits in a double.

Meta

Authors

Walter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara