parse

Integer parsing utilities.

  1. bool parse(Range r, T value)
  2. bool parse(Range r, T value)
  3. bool parse(Range r, T value)
  4. bool parse(Range r, T value)
  5. bool parse(Range r, T value)
  6. bool parse(Range r, T value)
  7. bool parse(Range r, T value)
    bool
    parse
    (
    T
    Range
    )
    (
    scope ref Range r
    ,
    scope ref T value
    )
    if (
    is(T == ulong) &&
    isInputRange!Range
    &&
    __traits(isUnsigned, T)
    )

Return Value

Type: bool

true if success and false otherwise.

Examples

import std.meta: AliasSeq;
foreach (T; AliasSeq!(byte, ubyte, short, ushort, int, uint, long, ulong))
{
    auto str = "123";
    T val;
    assert(parse(str, val));
    assert(val == 123);
    str = "0";
    assert(parse(str, val));
    assert(val == 0);
    str = "9";
    assert(parse(str, val));
    assert(val == 9);
    str = "";
    assert(!parse(str, val));
    assert(val == 0);
    str = "text";
    assert(!parse(str, val));
    assert(val == 0);
}
import std.meta: AliasSeq;
foreach (T; AliasSeq!(byte, short, int, long))
{
    auto str = "-123";
    T val;
    assert(parse(str, val));
    assert(val == -123);
    str = "-0";
    assert(parse(str, val));
    assert(val == 0);
    str = "-9text";
    assert(parse(str, val));
    assert(val == -9);
    assert(str == "text");
    enum m = T.min + 0;
    str = m.stringof;
    assert(parse(str, val));
    assert(val == T.min);
}

Meta