diff --git a/docs/utilities/expected.md b/docs/utilities/expected.md index f6cbcd63..8443a782 100644 --- a/docs/utilities/expected.md +++ b/docs/utilities/expected.md @@ -192,13 +192,13 @@ Swap with another etl::unexpected ```cpp template class expected -```cpp +``` Specialisation for void value type. ```cpp template class expected -```cpp +``` ### Types @@ -421,6 +421,7 @@ value_type& value() const Get the value. Undefined if has_value() returns false. Not valid for void specialisation. +Before: C++11 --- @@ -536,13 +537,46 @@ Before: C++11 --- +```cpp +template +ETL_NODISCARD +ETL_CONSTEXPR14 +error_type error_or(G&& default_error) const& +``` +**Description** +Returns default_error if has_value() returns true; otherwise returns the stored error. +Since: C++11 + +--- + +```cpp +template +ETL_NODISCARD +ETL_CONSTEXPR14 +error_type error_or(G&& default_error)&& +``` +**Description** +Returns default_error if has_value() returns true; otherwise returns the stored error. +Since: C++11 + +--- + +```cpp +template +error_type error_or(const G& default_error) const +``` +**Description** +Returns default_error if has_value() returns true; otherwise returns the stored error. +Before: C++11 + +--- + ```cpp template ETL_CONSTEXPR14 value_type& emplace(TArgs&&... args) ETL_NOEXCEPT ``` **Description** -Returns the error if has_value() returns false. -Undefined if has_value() returns true. +Create from arguments. Since: C++11 --- @@ -574,15 +608,411 @@ Const class member access operator. --- ```cpp -value_type& operator *() +value_type& operator *() & ``` -**Description** +**Description** Dereference operator. --- ```cpp -const value_type& operator *() const +const value_type& operator *() const& ``` -**Description** +**Description** Dereference operator. + +--- + +```cpp +value_type&& operator *() && +``` +**Description** +Dereference operator. +Since: C++11 + +--- + +```cpp +const value_type&& operator *() const&& +``` +**Description** +Dereference operator. +Since: C++11 + +--- + +```cpp +ETL_NODISCARD +ETL_CONSTEXPR14 +value_type* begin() ETL_NOEXCEPT +``` +**Description** +Returns a pointer to the value if has_value() returns true, otherwise returns nullptr. +Allows expected to be used as a range of 0 or 1 elements. Not valid for void specialisation. + +--- + +```cpp +ETL_NODISCARD +ETL_CONSTEXPR14 +const value_type* begin() const ETL_NOEXCEPT +``` +**Description** +Returns a pointer to the value if has_value() returns true, otherwise returns nullptr. Not valid for void specialisation. + +--- + +```cpp +ETL_NODISCARD +ETL_CONSTEXPR14 +value_type* end() ETL_NOEXCEPT +``` +**Description** +Returns a pointer past the value if has_value() returns true, otherwise returns nullptr. Not valid for void specialisation. + +--- + +```cpp +ETL_NODISCARD +ETL_CONSTEXPR14 +const value_type* end() const ETL_NOEXCEPT +``` +**Description** +Returns a pointer past the value if has_value() returns true, otherwise returns nullptr. Not valid for void specialisation. + +--- + +```cpp +template ::type>::type> +auto transform(F&& f) & -> expected +``` +**Description** +If has_value() returns true, it invokes f on the value and returns the result wrapped in an expected object; otherwise it returns an expected object that contains error(). For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform(F&& f) & -> expected +``` +**Description** +For void specialisation. +If has_value() returns true, it invokes f and returns the result wrapped in an expected object; otherwise it returns an expected object that contains error(). +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform(F&& f) const& -> expected +``` +**Description** +If has_value() returns true, it invokes f on the value and returns the result wrapped in an expected object; otherwise it returns an expected object that contains error(). For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform(F&& f) const& -> expected +``` +**Description** +For void specialisation. +If has_value() returns true, it invokes f and returns the result wrapped in an expected object; otherwise it returns an expected object that contains error(). +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform(F&& f) && -> expected +``` +**Description** +If has_value() returns true, it invokes f on the value and returns the result wrapped in an expected object; otherwise it returns an expected object that contains error(). For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform(F&& f) && -> expected +``` +**Description** +For void specialisation. +If has_value() returns true, it invokes f and returns the result wrapped in an expected object; otherwise it returns an expected object that contains error(). +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform(F&& f) const&& -> expected +``` +**Description** +If has_value() returns true, it invokes f and returns the result wrapped in an expected object; otherwise it returns an expected object that contains error(). For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform(F&& f) const&& -> expected +``` +**Description** +For void specialisation. +If has_value() returns true, it invokes f and returns the result wrapped in an expected object; otherwise it returns an expected object that contains error(). +Since: C++11 + +--- + +```cpp +template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> +auto and_then(F&& f) & -> U +``` +**Description** +If has_value() returns true, it invokes f on the value and returns the result; otherwise it returns an expected object that contains error(). For void specialisation see below. +Since: C++11 + +--- + +```cpp +template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type> +auto and_then(F&& f) & -> U +``` +**Description** +For void specialisation. +If has_value() returns true, it invokes f and returns the result; otherwise it returns an expected object that contains error(). +Since: C++11 + +--- + +```cpp +template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> +auto and_then(F&& f) const& -> U +``` +**Description** +If has_value() returns true, it invokes f on the value and returns the result; otherwise it returns an expected object that contains error(). For void specialisation see below. +Since: C++11 + +--- + +```cpp +template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> +auto and_then(F&& f) const& -> U +``` +**Description** +For void specialisation. +If has_value() returns true, it invokes f and returns the result; otherwise it returns an expected object that contains error(). +Since: C++11 + +--- + +```cpp +template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> +auto and_then(F&& f) && -> U +``` +**Description** +If has_value() returns true, it invokes f on the value and returns the result; otherwise it returns an expected object that contains error(). For void specialisation see below. +Since: C++11 + +--- + +```cpp +template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> +auto and_then(F&& f) && -> U +``` +**Description** +For void specialisation. +If has_value() returns true, it invokes f and returns the result; otherwise it returns an expected object that contains error(). +Since: C++11 + +--- + +```cpp +template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> +auto and_then(F&& f) const&& -> U +``` +**Description** +If has_value() returns true, it invokes f on the value and returns the result; otherwise it returns an expected object that contains error(). For void specialisation see below. +Since: C++11 + +--- + +```cpp +template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> +auto and_then(F&& f) const&& -> U +``` +**Description** +For void specialisation. +If has_value() returns true, it invokes f and returns the result; otherwise it returns an expected object that contains error(). +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto or_else(F&& f) & -> U +``` +**Description** +If has_value() returns true, it returns an expected object that contains value(); otherwise it invokes f on error() and returns the result. For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto or_else(F&& f) & -> U +``` +**Description** +For void specialisation. +If has_value() returns true, it returns a default constructed expected object of the appropriate type; otherwise it invokes f on error() and returns the result. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto or_else(F&& f) const& -> U +``` +**Description** +If has_value() returns true, it returns an expected object that contains value(); otherwise it invokes f on error() and returns the result. For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto or_else(F&& f) const& -> U +``` +**Description** +For void specialisation. +If has_value() returns true, it returns a default constructed expected object of the appropriate type; otherwise it invokes f on error() and returns the result. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto or_else(F&& f) && -> U +``` +**Description** +If has_value() returns true, it returns an expected object that contains value(); otherwise it invokes f on error() and returns the result. For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto or_else(F&& f) && -> U +``` +**Description** +For void specialisation. +If has_value() returns true, it returns a default constructed expected object of the appropriate type; otherwise it invokes f on error() and returns the result. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto or_else(F&& f) const&& -> U +``` +**Description** +If has_value() returns true, it returns an expected object that contains value(); otherwise it invokes f on error() and returns the result. For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto or_else(F&& f) const&& -> U +``` +**Description** +For void specialisation. +If has_value() returns true, it returns a default constructed expected object of the appropriate type; otherwise it invokes f on error() and returns the result. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform_error(F&& f) & -> expected +``` +**Description** +If has_value() returns true, it returns an expected that contains value(); otherwise it invokes f on error() and returns the result wrapped in an expected object. For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform_error(F&& f) & -> expected +``` +**Description** +For void specialisation. +If has_value() returns true, it returns a default constructed expected object of the appropriate type; otherwise it invokes f on error() and returns the result wrapped in an expected object. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform_error(F&& f) const& -> expected +``` +**Description** +If has_value() returns true, it returns an expected that contains value(); otherwise it invokes f on error() and returns the result wrapped in an expected object. For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform_error(F&& f) const& -> expected +``` +**Description** +For void specialisation. +If has_value() returns true, it returns a default constructed expected object of the appropriate type; otherwise it invokes f on error() and returns the result wrapped in an expected object. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform_error(F&& f) && -> expected +``` +**Description** +If has_value() returns true, it returns an expected that contains value(); otherwise it invokes f on error() and returns the result wrapped in an expected object. For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform_error(F&& f) && -> expected +``` +**Description** +For void specialisation. +If has_value() returns true, it returns a default constructed expected object of the appropriate type; otherwise it invokes f on error() and returns the result wrapped in an expected object. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform_error(F&& f) const&& -> expected +``` +**Description** +If has_value() returns true, it returns an expected that contains value(); otherwise it invokes f on error() and returns the result wrapped in an expected object. For void specialisation see below. +Since: C++11 + +--- + +```cpp +template ::type>::type> +auto transform_error(F&& f) const&& -> expected +``` +**Description** +For void specialisation. +If has_value() returns true, it returns a default constructed expected object of the appropriate type; otherwise it invokes f on error() and returns the result wrapped in an expected object. +Since: C++11 +