diff --git a/doc/27_ref_optional_synopsis.qbk b/doc/27_ref_optional_synopsis.qbk index 8454218..5d4c2e4 100644 --- a/doc/27_ref_optional_synopsis.qbk +++ b/doc/27_ref_optional_synopsis.qbk @@ -260,6 +260,8 @@ They are empty, trivially copyable classes with disabled default constructor. template T& value_or_eval( F f ) const ; ``[link reference_optional_ref_value_or_eval __GO_TO__]`` + template auto map( F f ) const -> ``['see below]``; ``[link reference_optional_ref_map __GO_TO__]`` + T* get_ptr() const noexcept ; ``[link reference_optional_ref_get_ptr __GO_TO__]`` bool has_value() const noexcept ; ``[link reference_optional_ref_operator_bool __GO_TO__]`` diff --git a/doc/28_ref_optional_semantics.qbk b/doc/28_ref_optional_semantics.qbk index 320da2d..b615e35 100644 --- a/doc/28_ref_optional_semantics.qbk +++ b/doc/28_ref_optional_semantics.qbk @@ -687,20 +687,20 @@ __SPACE__ [#reference_optional_map] -[: `template auto optional::map(F f) const& -> ``['see below]`` ;`] -[: `template auto optional::map(F f) & -> ``['see below]`` ;`] +[: `template auto optional::map(F f) const& -> `['see below]` ;`] +[: `template auto optional::map(F f) & -> `['see below]` ;`] * [*Effects:] `if (*this) return f(**this); else return none;` -* [*Notes:] The return type of these overloads is `optional`. On compilers that do not support ref-qualifiers on member functions, these two (as well as the next one) overloads are replaced with good old const and non-const overloads. +* [*Notes:] The return type of these overloads is `optional`. On compilers that do not support ref-qualifiers on member functions, these two (as well as the next one) overloads are replaced with good old const and non-const overloads. __SPACE__ [#reference_optional_map_move] -[: `template auto optional::map(F f) && -> ``['see below]`` ;`] +[: `template auto optional::map(F f) && -> `['see below]` ;`] * [*Effects:] `if (*this) return f(std::move(**this)); else return none;` -* [*Notes:] The return type of this overload is `optional`. +* [*Notes:] The return type of this overload is `optional`. __SPACE__ @@ -1053,6 +1053,13 @@ __SPACE__ __SPACE__ +[#reference_optional_ref_map] +[: `template auto optional::map( F f ) const -> `['see below]`;`] +* [*Effects:] Equivalent to `if (*this) return f(**this); else return none;`. +* [*Remarks:] The return type of this function is `optional`. + +__SPACE__ + [#reference_optional_ref_get_ptr] [: `T* optional::get_ptr () const noexcept;`] * [*Returns:] `ref`. diff --git a/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics___optional_references.html b/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics___optional_references.html index 3101217..acb6775 100644 --- a/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics___optional_references.html +++ b/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics___optional_references.html @@ -407,6 +407,21 @@ is ill-formed. +

+ space +

+

+ template<class F> auto optional<T&>::map( F f ) const -> see below; +

+
    +
  • + Effects: Equivalent to if (*this) return f(**this); else return none;. +
  • +
  • + Remarks: The return type of this function + is optional<decltype(f(**this))>. +
  • +

space

diff --git a/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics___optional_values.html b/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics___optional_values.html index 46fe0a8..127df4c 100644 --- a/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics___optional_values.html +++ b/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics___optional_values.html @@ -1476,10 +1476,10 @@

template<class F> auto optional<T>::map(F f) const& -> - ['see below] ; + see below ;

- template<class F> auto optional<T>::map(F f) & -> ['see below] + template<class F> auto optional<T>::map(F f) & -> see below ;

    @@ -1490,7 +1490,7 @@
  • Notes: The return type of these overloads - is optional<decltype(f(**this)>. + is optional<decltype(f(**this))>. On compilers that do not support ref-qualifiers on member functions, these two (as well as the next one) overloads are replaced with good old const and non-const overloads. @@ -1501,7 +1501,7 @@

    template<class F> auto optional<T>::map(F f) && - -> ['see below] + -> see below ;

      @@ -1512,7 +1512,7 @@
    • Notes: The return type of this overload - is optional<decltype(f(istd::move(**this))>. + is optional<decltype(f(istd::move(**this)))>.

    diff --git a/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_optional_refs.html b/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_optional_refs.html index 3934957..77906eb 100644 --- a/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_optional_refs.html +++ b/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_optional_refs.html @@ -73,6 +73,8 @@ template<class F> T& value_or_eval( F f ) const ; R + template<class F> auto map( F f ) const -> see below; R + T* get_ptr() const noexcept ; R bool has_value() const noexcept ; R diff --git a/doc/html/index.html b/doc/html/index.html index a37010c..44e9bc0 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -145,7 +145,7 @@

- +

Last revised: June 23, 2018 at 16:25:31 GMT

Last revised: June 23, 2018 at 18:49:36 GMT


diff --git a/test/optional_test_map.cpp b/test/optional_test_map.cpp index 9a9aab2..19348bd 100644 --- a/test/optional_test_map.cpp +++ b/test/optional_test_map.cpp @@ -106,6 +106,34 @@ void test_map() optional oI = oi.map(convert_t()); BOOST_TEST(bool(oI)); BOOST_TEST_EQ(1, oI->i); + + optional o_ = optional().map(convert_t()); + BOOST_TEST(!o_); +} + +optional make_opt_int(int i) +{ + if (i != 0) + return Int(i); + else + return boost::none; +} + +void test_map_optional() +{ + optional o9 (9), o0 (0), o_; + verify_type>>(o9.map(make_opt_int)); + optional> oo9 = o9.map(make_opt_int); + BOOST_TEST(bool(oo9)); + BOOST_TEST(bool(*oo9)); + BOOST_TEST_EQ(9, (**oo9).i); + + optional> oo0 = o0.map(make_opt_int); + BOOST_TEST(bool(oo0)); + BOOST_TEST(!*oo0); + + optional> oo_ = o_.map(make_opt_int); + BOOST_TEST(!oo_); } void test_map_with_lambda() @@ -153,7 +181,9 @@ int main() #endif test_map_with_lambda(); test_map(); + test_map_optional(); test_map_to_ref(); + test_map_optional(); test_map_optional_ref(); return boost::report_errors();