to string conversion
alias T = int; alias R = Result!T; const R r1; assert(r1.toString == "invalid"); const R r2 = 42; assert(r2.toString == "42"); R r3 = r2; r3 = 42; assert(*r3 == 42); assert(r3 == 42); T v42 = 42; assert(r3 == v42);
result of uncopyable type
alias T = Uncopyable; alias R = Result!T; const R r_ = R(T.init); R r1; assert(!r1); assert(r1 != r_); assert(!r1.isValue); T t = T(42); r1 = move(t); assert(r1 != r_); assert(*r1 == T(42)); R r2 = T(43); assert(*r2 == T(43)); assert(r2.value == T(43));
result of pointer and error enum
alias V = ulong; alias T = V*; enum E { first, second } alias R = Result!(T, E); R r1; assert(!r1); assert(r1 == R.invalid); assert(r1 != R(T.init)); assert(!r1.isValue); assert(r1.isError); assert(r1.error == E.init); assert(r1.error == E.first); T v = new V(42); r1 = move(v); assert(r1 != R(T.init)); assert(**r1 == V(42));
result of pointer and error enum toString
alias V = ulong; alias T = V*; enum E { first, second } alias R = Result!(T, E); R r1; assert(r1.toString == "first"); r1 = T.init; assert(r1.toString == "null");
result of pointer and error enum
alias V = ulong; alias T = V*; enum E { first, second } alias R = Result!(T, E); R r2 = new V(43); assert(**r2 == V(43)); assert(*r2.value == V(43));
result of pointer and error enum
alias V = ulong; alias T = V*; enum E { first, second } alias R = Result!(T, E); R r2 = E.first; assert(r2.error == E.first); r2 = E.second; assert(r2.error == E.second);
Result of T with optional error E. Designed for error handling where an operation can either succeed or fail. - TODO: Add member toRange alias with opSlice - TODO: Add member visit()