ok

Creates an Expected object from an expected value, with type inference.

  1. Expected!(T, E, Hook) ok(T value)
  2. Expected!(void, E, Hook) ok()
    Expected!(void, E, Hook)
    ok
    (
    E = string
    Hook = Abort
    )
    ()

Examples

// void
{
    auto res = ok();
    static assert(is(typeof(res) == Expected!(void, string)));
    assert(res);
}

// int
{
    auto res = ok(42);
    static assert(is(typeof(res) == Expected!(int, string)));
    assert(res);
    assert(res.value == 42);
}

// string
{
    auto res = ok("42");
    static assert(is(typeof(res) == Expected!(string, string)));
    assert(res);
    assert(res.value == "42");
}

// other error type
{
    auto res = ok!bool(42);
    static assert(is(typeof(res) == Expected!(int, bool)));
    assert(res);
    assert(res.value == 42);
}

Meta