From fd971bca70879ffeff092c53b5e67047aa9b0557 Mon Sep 17 00:00:00 2001 From: Marton Szasz Date: Sat, 30 Sep 2023 08:26:13 +0200 Subject: [PATCH] update README --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 6a621ec..9d6fb98 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,16 @@ Define this to 1 or 0 to control the use of SEH when C++ exceptions are disabled \-Dnsel\_CONFIG\_CONFIRMS\_COMPILATION\_ERRORS=0 Define this macro to 1 to experience the by-design compile-time errors of the library in the test suite. Default is 0. +#### Configure P2505 monadic operations + +By default, *expected lite* provides monadic operations as described in [P2505R5](http://wg21.link/p2505r5). You can disable these operations by defining the following macro. + +-Dnsel\_P2505R= + +You can use the R3 revision of P2505, which lacks `error_or`, and uses `remove_cvref` for transforms, by defining the following macro. + +-Dnsel\_P2505R=3 + ### Types in namespace nonstd | Purpose | Type | Note / Object | @@ -182,6 +192,24 @@ Define this macro to 1 to experience the by-design compile-time errors of the li |   | template<typename Ex>
bool **has_exception**() const | true of contains exception (as base) | |   | value_type **value_or**( U && v ) const & | value or move from v | |   | value_type **value_or**( U && v ) && | move from value or move from v | +|   | constexpr error_type **error_or**( G && e ) const & | return current error or v [requires nsel_P2505R >= 4] | +|   | constexpr error_type **error_or**( G && e ) && | move from current error or from v [requires nsel_P2505R >=4] | +| Monadic operations
(requires nsel_P2505R >= 3) | constexpr auto **and_then**( F && f ) & G| return f(value()) if has value, otherwise the error | +|   | constexpr auto **and_then**( F && f ) const & | return f(value()) if has value, otherwise the error | +|   | constexpr auto **and_then**( F && f ) && | return f(std::move(value())) if has value, otherwise the error | +|   | constexpr auto **and_then**( F && f ) const && | return f(std::move(value())) if has value, otherwise the error | +|   | constexpr auto **or_else**( F && f ) & | return the value, or f(error()) if there is no value | +|   | constexpr auto **or_else**( F && f ) const & | return the value, or f(error()) if there is no value | +|   | constexpr auto **or_else**( F && f ) && | return the value, or f(std::move(error())) if there is no value | +|   | constexpr auto **or_else**( F && f ) const && | return the value, or f(std::move(error())) if there is no value | +|   | constexpr auto **transform**( F && f ) & | return f(value()) wrapped if has value, otherwise the error | +|   | constexpr auto **transform**( F && f ) const & | return f(value()) wrapped if has value, otherwise the error | +|   | constexpr auto **transform**( F && f ) && | return f(std::move(value())) wrapped if has value, otherwise the error | +|   | constexpr auto **transform**( F && f ) const && | return f(std::move(value())) wrapped if has value, otherwise the error | +|   | constexpr auto **transform_error**( F && f ) & | return the value if has value, or f(error()) otherwise | +|   | constexpr auto **transform_error**( F && f ) const & | return the value if has value, or f(error()) otherwise | +|   | constexpr auto **transform_error**( F && f ) && | return the value if has value, or f(std::move(error())) otherwise | +|   | constexpr auto **transform_error**( F && f ) const && | return the value if has value, or f(std::move(error())) otherwise | |   | ... |   | Note 1: checked access: if no content, for std::exception_ptr rethrows error(), otherwise throws bad_expected_access(error()). @@ -425,6 +453,11 @@ expected: Allows to query if it contains an exception of a specific base type expected: Allows to observe its value if available, or obtain a specified value otherwise expected: Allows to move its value if available, or obtain a specified value otherwise expected: Throws bad_expected_access on value access when disengaged +expected: Allows to observe its unexpected value, or fallback to the specified value with error_or +expected: Allows to map value with and_then +expected: Handling unexpected with or_else +expected: transform values +expected: Mapping errors with transform_error expected: Allows to default-construct expected: Allows to copy-construct from expected: value expected: Allows to copy-construct from expected: error @@ -451,6 +484,11 @@ expected: Allows to move its error expected: Allows to observe its error as unexpected expected: Allows to query if it contains an exception of a specific base type expected: Throws bad_expected_access on value access when disengaged +expected: Observe unexpected value, or fallback to a default value with error_or +expected: calling argless functions with and_then +expected: or_else unexpected handling works +expected: using transform to assign a new expected value +expected: transform_error maps unexpected values operators: Provides expected relational operators operators: Provides expected relational operators (void) swap: Allows expected to be swapped