From e47a01700940654f3f9e461ac422f55a8d0ed0c8 Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Sat, 23 Jun 2018 18:27:14 +0200 Subject: [PATCH] added o.map() --- doc/00_optional.qbk | 2 +- doc/27_ref_optional_synopsis.qbk | 4 + doc/28_ref_optional_semantics.qbk | 19 +++ doc/91_relnotes.qbk | 1 + doc/html/boost_optional/acknowledgements.html | 3 +- .../dependencies_and_portability.html | 3 +- ...emplace_operations_in_older_compilers.html | 3 +- .../optional_reference_binding.html | 3 +- doc/html/boost_optional/quick_start.html | 3 +- ...sing_unnecessary_default_construction.html | 3 +- .../optional_automatic_variables.html | 3 +- .../quick_start/optional_data_members.html | 3 +- .../quick_start/storage_in_containers.html | 3 +- ...ost_optional_bad_optional_access_hpp_.html | 3 +- .../detailed_semantics.html | 3 +- .../header__boost_optional_hpp_.html | 3 +- ...der__boost_optional_optional_fwd_hpp_.html | 3 +- .../detailed_semantics___free_functions.html | 3 +- ...ailed_semantics___optional_references.html | 3 +- .../detailed_semantics___optional_values.html | 47 ++++- .../header_optional_in_place_init.html | 3 +- .../header_optional_optional_refs.html | 3 +- .../header_optional_optional_values.html | 7 +- .../boost_optional/reference/io_header.html | 3 +- .../reference/io_header/io_semantics.html | 3 +- doc/html/boost_optional/relnotes.html | 12 +- .../tutorial/design_overview.html | 3 +- .../design_overview/the_interface.html | 3 +- .../design_overview/the_semantics.html | 3 +- .../tutorial/exception_safety_guarantees.html | 3 +- doc/html/boost_optional/tutorial/gotchas.html | 3 +- ...e_positive_with__wmaybe_uninitialized.html | 3 +- .../gotchas/mixed_relational_comparisons.html | 3 +- .../gotchas/moved_from__optional_.html | 3 +- .../tutorial/in_place_factories.html | 3 +- .../boost_optional/tutorial/io_operators.html | 3 +- .../tutorial/optional_references.html | 3 +- ...for_assignment_of_optional_references.html | 3 +- .../tutorial/performance_considerations.html | 3 +- .../tutorial/relational_operators.html | 3 +- .../tutorial/type_requirements.html | 3 +- .../tutorial/when_to_use_optional.html | 3 +- doc/html/index.html | 5 +- doc/html/optional/reference.html | 3 +- .../header__boost_optional_optional_hpp_.html | 3 +- doc/html/optional/tutorial.html | 3 +- .../detail/optional_reference_spec.hpp | 11 +- include/boost/optional/optional.hpp | 51 +++++- test/Jamfile.v2 | 1 + test/optional_test_map.cpp | 160 ++++++++++++++++++ 50 files changed, 343 insertions(+), 91 deletions(-) create mode 100644 test/optional_test_map.cpp diff --git a/doc/00_optional.qbk b/doc/00_optional.qbk index 02e21f4..00b6096 100644 --- a/doc/00_optional.qbk +++ b/doc/00_optional.qbk @@ -2,7 +2,7 @@ [quickbook 1.4] [authors [Cacciola Carballal, Fernando Luis]] [copyright 2003-2007 Fernando Luis Cacciola Carballal] - [copyright 2014-2017 Andrzej Krzemieński] + [copyright 2014-2018 Andrzej Krzemieński] [category miscellaneous] [id optional] [dirname optional] diff --git a/doc/27_ref_optional_synopsis.qbk b/doc/27_ref_optional_synopsis.qbk index 1a6a849..8454218 100644 --- a/doc/27_ref_optional_synopsis.qbk +++ b/doc/27_ref_optional_synopsis.qbk @@ -179,6 +179,10 @@ They are empty, trivially copyable classes with disabled default constructor. template T value_or_eval( F f ) const& ; ``[link reference_optional_value_or_call __GO_TO__]`` template T value_or_eval( F f ) && ; ``[link reference_optional_value_or_call_move __GO_TO__]`` + template auto map( F f ) const& -> ``['see below]``; ``[link reference_optional_map __GO_TO__]`` + template auto map( F f ) & -> ``['see below]``; ``[link reference_optional_map __GO_TO__]`` + template auto map( F f ) && -> ``['see below]``; ``[link reference_optional_map_move __GO_TO__]`` + T const* get_ptr() const ; ``[link reference_optional_get_ptr __GO_TO__]`` T* get_ptr() ; ``[link reference_optional_get_ptr __GO_TO__]`` diff --git a/doc/28_ref_optional_semantics.qbk b/doc/28_ref_optional_semantics.qbk index 8c1397f..320da2d 100644 --- a/doc/28_ref_optional_semantics.qbk +++ b/doc/28_ref_optional_semantics.qbk @@ -685,6 +685,25 @@ __SPACE__ __SPACE__ +[#reference_optional_map] + +[: `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. + +__SPACE__ + +[#reference_optional_map_move] + +[: `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`. + +__SPACE__ + [#reference_optional_get_value_or_value] [: `T const& optional::get_value_or( T const& default) const ;`] diff --git a/doc/91_relnotes.qbk b/doc/91_relnotes.qbk index 93e9799..79bb200 100644 --- a/doc/91_relnotes.qbk +++ b/doc/91_relnotes.qbk @@ -14,6 +14,7 @@ [heading Boost Release 1.68] * Added member function `has_value()` for compatibility with `std::optional` ([@https://github.com/boostorg/optional/issues/52 issue #52]). +* Added member function `map()` for transforming `optional` into `optional` using a function of type `U(T)`. [heading Boost Release 1.67] diff --git a/doc/html/boost_optional/acknowledgements.html b/doc/html/boost_optional/acknowledgements.html index f91a9f2..c6f9f2f 100644 --- a/doc/html/boost_optional/acknowledgements.html +++ b/doc/html/boost_optional/acknowledgements.html @@ -116,8 +116,7 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

+ space +

+

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

+

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

+
    +
  • + Effects: if + (*this) return f(**this); else return + none; +
  • +
  • + Notes: The return type of these overloads + 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. +
  • +
+

+ space +

+

+ template<class F> auto optional<T>::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<decltype(f(istd::move(**this))>. +
  • +

space

@@ -1654,8 +1698,7 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -146,7 +145,7 @@

- +

Last revised: March 23, 2018 at 23:01:17 GMT

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


diff --git a/doc/html/optional/reference.html b/doc/html/optional/reference.html index da63269..d3b0ab7 100644 --- a/doc/html/optional/reference.html +++ b/doc/html/optional/reference.html @@ -75,8 +75,7 @@ -
-
-