template <typename V = void, typename E = void>

class result

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");

}

Public Methods

void result<V, E> ()

Creates a pending result.

Defined at line 127 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

void result<V, E> (pending_result )

Defined at line 128 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

void result<V, E> (ok_result<V> result)

Creates an ok result.

Defined at line 131 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

template <typename OtherV, typename = std::enable_if_t<std::is_constructible<V, OtherV>::value>>
void result<V, E> (ok_result<OtherV> other)

Defined at line 133 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

void result<V, E> (error_result<E> result)

Creates an error result.

Defined at line 137 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

template <typename OtherE, typename = std::enable_if_t<std::is_constructible<E, OtherE>::value>>
void result<V, E> (error_result<OtherE> other)

Defined at line 139 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

void result<V, E> (const result<V, E> & other)

Copies another result (if copyable).

Defined at line 143 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

void result<V, E> (result<V, E> && other)

Moves from another result, leaving the other one in a pending state.

Defined at line 146 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

void ~result<V, E> ()

Defined at line 148 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

result_state state ()

Returns the state of the task's result: pending, ok, or error.

Defined at line 151 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

bool operator bool ()

Returns true if the result is not pending.

Defined at line 154 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

bool is_pending ()

Returns true if the task is still in progress.

Defined at line 157 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

bool is_ok ()

Returns true if the task succeeded.

Defined at line 160 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

bool is_error ()

Returns true if the task failed.

Defined at line 163 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

template <typename R = V, typename = std::enable_if_t<!std::is_void<R>::value>>
R & value ()

Gets the result's value.

Asserts that the result's state is |fpromise::result_state::ok|.

Defined at line 168 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

template <typename R = V, typename = std::enable_if_t<!std::is_void<R>::value>>
const R & value ()

Defined at line 172 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

template <typename R = V, typename = std::enable_if_t<!std::is_void<R>::value>>
R take_value ()

Takes the result's value, leaving it in a pending state.

Asserts that the result's state is |fpromise::result_state::ok|.

Defined at line 179 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

ok_result<V> take_ok_result ()

Defined at line 184 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

template <typename R = E, typename = std::enable_if_t<!std::is_void<R>::value>>
R & error ()

Gets a reference to the result's error.

Asserts that the result's state is |fpromise::result_state::error|.

Defined at line 193 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

template <typename R = E, typename = std::enable_if_t<!std::is_void<R>::value>>
const R & error ()

Defined at line 197 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

template <typename R = E, typename = std::enable_if_t<!std::is_void<R>::value>>
R take_error ()

Takes the result's error, leaving it in a pending state.

Asserts that the result's state is |fpromise::result_state::error|.

Defined at line 204 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

error_result<E> take_error_result ()

Defined at line 209 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

result<V, E> & operator= (const result<V, E> & other)

Assigns from another result (if copyable).

Defined at line 216 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

result<V, E> & operator= (result<V, E> && other)

Moves from another result, leaving the other one in a pending state.

Defined at line 219 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

void swap (result<V, E> & other)

Swaps results.

Defined at line 226 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h