to

Converts a stringish range to an integral value.

  1. template to(To)
  2. To to(From from)
  3. To to(From from)
  4. To to(From from)
  5. To to(From from)
  6. To to(From from)
  7. To to(From from)
  8. To to(From from)
    To
    to
    (
    To
    From
    )
    (
    auto ref From from
    )
    if (
    isInputRange!From &&
    isSomeChar!(ElementType!From)
    &&
    )

Parameters

From

Source type.

To

Target type.

from From

Source value.

Return Value

Type: To

from converted to To.

Throws

$(D_PSYMBOL ConvException) if from doesn't contain an integral value.

Examples

assert("1234".to!uint() == 1234);
assert("1234".to!int() == 1234);
assert("1234".to!int() == 1234);

assert("0".to!int() == 0);
assert("-0".to!int() == 0);

assert("0x10".to!int() == 16);
assert("0X10".to!int() == 16);
assert("-0x10".to!int() == -16);

assert("0b10".to!int() == 2);
assert("0B10".to!int() == 2);
assert("-0b10".to!int() == -2);

assert("010".to!int() == 8);
assert("-010".to!int() == -8);

assert("-128".to!byte == cast(byte) -128);

Meta