From d2f8a4298028cc9f517895a946e735ac392676b5 Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Sun, 14 May 2017 16:31:00 +0200 Subject: [PATCH 1/6] Adds forwarding make_optional helpers, resolves #30 --- include/boost/optional/optional.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index a465b9ed..e578a393 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -1276,6 +1276,25 @@ class optional namespace boost { +#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES + +template +inline +optional::type> make_optional ( T && v ) +{ + return optional::type>(boost::forward(v)); +} + +// Returns optional(cond,v) +template +inline +optional::type> make_optional ( bool cond, T && v ) +{ + return optional::type>(cond,boost::forward(v)); +} + +#else + // Returns optional(v) template inline @@ -1292,6 +1311,8 @@ optional make_optional ( bool cond, T const& v ) return optional(cond,v); } +#endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES + // Returns a reference to the value if this is initialized, otherwise, the behaviour is UNDEFINED. // No-throw template From 19eee3dad09c78d0a1ea726d70e7921154b02a57 Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Thu, 18 May 2017 01:09:31 +0200 Subject: [PATCH 2/6] Fix make_optional for rvalues --- doc/00_optional.qbk | 2 +- doc/27_ref_optional_synopsis.qbk | 4 + doc/28_ref_optional_semantics.qbk | 18 +++ 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 | 29 ++++- ...ailed_semantics___optional_references.html | 3 +- .../detailed_semantics___optional_values.html | 3 +- .../header_optional_in_place_init.html | 3 +- .../header_optional_optional_refs.html | 3 +- .../header_optional_optional_values.html | 3 +- .../boost_optional/reference/io_header.html | 3 +- .../reference/io_header/io_semantics.html | 3 +- doc/html/boost_optional/relnotes.html | 3 +- .../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 | 7 +- doc/html/optional/tutorial.html | 3 +- include/boost/optional/optional.hpp | 19 +++ test/Jamfile.v2 | 1 + test/optional_test_make_optional.cpp | 122 ++++++++++++++++++ 48 files changed, 280 insertions(+), 44 deletions(-) create mode 100644 test/optional_test_make_optional.cpp diff --git a/doc/00_optional.qbk b/doc/00_optional.qbk index e6ebc4c6..02e21f46 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-2016 Andrzej Krzemieński] + [copyright 2014-2017 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 2da3b8f9..f93076eb 100644 --- a/doc/27_ref_optional_synopsis.qbk +++ b/doc/27_ref_optional_synopsis.qbk @@ -44,8 +44,12 @@ template inline bool operator != ( optional const& x, none_t ) noexcept ; ``[link reference_operator_compare_not_equal_optional_none __GO_TO__]`` template inline optional make_optional ( T const& v ) ; ``[link reference_make_optional_value __GO_TO__]`` + + template inline optional> make_optional ( T && v ) ; ``[link reference_make_optional_rvalue __GO_TO__]`` template inline optional make_optional ( bool condition, T const& v ) ; ``[link reference_make_optional_bool_value __GO_TO__]`` + + template inline optional> make_optional ( bool condition, T && v ) ; ``[link reference_make_optional_bool_rvalue __GO_TO__]`` template inline auto get_optional_value_or ( optional const& opt, typename optional::reference_const_type def ) -> typename optional::reference_const_type; ``[link reference_free_get_value_or __GO_TO__]`` diff --git a/doc/28_ref_optional_semantics.qbk b/doc/28_ref_optional_semantics.qbk index 1288c565..7e2740c0 100644 --- a/doc/28_ref_optional_semantics.qbk +++ b/doc/28_ref_optional_semantics.qbk @@ -1097,6 +1097,15 @@ template void foo ( optional const& opt ) ; foo ( make_optional(1+1) ) ; // Creates an optional `` +__SPACE__ + +[#reference_make_optional_rvalue] + +[: `optional> make_optional( T && v )`] + +* [*Returns: ] `optional>(std::move(v))` for the ['deduced] type `T` of `v`. + + __SPACE__ [#reference_make_optional_bool_value] @@ -1117,6 +1126,15 @@ if ( !v ) error("foo wasn't computed"); `` +__SPACE__ + +[#reference_make_optional_bool_rvalue] + +[: `optional> make_optional( bool condition, T && v )`] + +* [*Returns: ] `optional>(condition, std::move(v))` for the ['deduced] type `T` of `v`. + + __SPACE__ [#reference_operator_compare_equal_optional_optional] diff --git a/doc/html/boost_optional/acknowledgements.html b/doc/html/boost_optional/acknowledgements.html index 2cd116c2..9d07002c 100644 --- a/doc/html/boost_optional/acknowledgements.html +++ b/doc/html/boost_optional/acknowledgements.html @@ -116,7 +116,8 @@

-
-
-
-
-
-
-
-
-
-
-
-
-
+

+ space +

+

+ optional<std::decay_t<T>> + make_optional( + T && + v ) +

+
  • + Returns: optional<std::decay_t<T>>(std::move(v)) for the deduced + type T of v. +

space

@@ -73,6 +86,19 @@ +

+ space +

+

+ optional<std::decay_t<T>> + make_optional( + bool condition, T && v + ) +

+
  • + Returns: optional<std::decay_t<T>>(condition, std::move(v)) for the deduced + type T of v. +

space

@@ -481,7 +507,8 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

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

- +

Last revised: February 14, 2017 at 22:51:08 GMT

Last revised: May 17, 2017 at 23:01:39 GMT


diff --git a/doc/html/optional/reference.html b/doc/html/optional/reference.html index 1c9b7927..fe13339a 100644 --- a/doc/html/optional/reference.html +++ b/doc/html/optional/reference.html @@ -75,7 +75,8 @@ -
-
-