Defined at line 121 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Represents the result of a task which may have succeeded, failed, or still be in progress.
Use |fpromise::pending()|, |fpromise::ok<T>()|, or |fpromise::error<T>| to initialize the result.
|V| is the type of value produced when the completes successfully. Defaults to |void|.
|E| is the type of error produced when the completes with an error. Defaults to |void|.
EXAMPLE:
fpromise::result<int, std::string> divide(int dividend, int divisor) { if (divisor == 0) return fpromise::error<std::string>("divide by zero"); return fpromise::ok(dividend / divisor); }
int try_divide(int dividend, int divisor) { auto result = divide(dividend, divisor); if (result.is_ok()) { printf("%d / %d = %d\n", dividend, divisor, result.value()); return result.value(); } printf("%d / %d: ERROR %s\n", dividend, divisor, result.error().c_str()); return -999; }
EXAMPLE WITH VOID RESULT VALUE AND ERROR:
fpromise::result<> open(std::string secret) { printf("guessing \"%s"", secret.c_str()); if (secret == "sesame") { return fpromise::ok(); puts("yes!"); } puts("no."); return fpromise::error(); }
bool guess_combination() { return open("friend") || open("sesame") || open("I give up"); }
result<V, E>
public void result<V, E>()
Defined at line 127 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Creates a pending result.
result<V, E>
public void result<V, E>(
pending_result
)
Defined at line 128 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
result<V, E>
public void result<V, E>(ok_result<V> result)
Defined at line 131 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
result<V, E>
public void result<V, E>(ok_result<OtherV> other)
Defined at line 133 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
result<V, E>
public void result<V, E>(error_result<E> result)
Defined at line 137 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
result<V, E>
public void result<V, E>(error_result<OtherE> other)
Defined at line 139 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
result<V, E>
public void result<V, E>(const result<V, E> & other)
Defined at line 143 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Copies another result (if copyable).
result<V, E>
public void result<V, E>(result<V, E> && other)
Defined at line 146 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Moves from another result, leaving the other one in a pending state.
~result<V, E>
public void ~result<V, E>()
Defined at line 148 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
state
public
result_state
state()
Defined at line 151 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Returns the state of the task's result: pending, ok, or error.
operator bool
public bool operator bool()
Defined at line 154 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Returns true if the result is not pending.
is_pending
public bool is_pending()
Defined at line 157 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Returns true if the task is still in progress.
is_ok
public bool is_ok()
Defined at line 160 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Returns true if the task succeeded.
is_error
public bool is_error()
Defined at line 163 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Returns true if the task failed.
value
public R & value()
Defined at line 168 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Gets the result's value. Asserts that the result's state is |fpromise::result_state::ok|.
value
public const R & value()
Defined at line 172 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
take_value
public R take_value()
Defined at line 179 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Takes the result's value, leaving it in a pending state. Asserts that the result's state is |fpromise::result_state::ok|.
take_ok_result
public ok_result<V> take_ok_result()
Defined at line 184 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
error
public R & error()
Defined at line 193 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Gets a reference to the result's error. Asserts that the result's state is |fpromise::result_state::error|.
error
public const R & error()
Defined at line 197 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
take_error
public R take_error()
Defined at line 204 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Takes the result's error, leaving it in a pending state. Asserts that the result's state is |fpromise::result_state::error|.
take_error_result
public error_result<E> take_error_result()
Defined at line 209 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
operator=
public result<V, E> & operator=(const result<V, E> & other)
Defined at line 216 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Assigns from another result (if copyable).
operator=
public result<V, E> & operator=(result<V, E> && other)
Defined at line 219 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h
Moves from another result, leaving the other one in a pending state.
swap
public void swap(result<V, E> & other)
Defined at line 226 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h