From c695be11b56a90e03e469560854d9b3505049d10 Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Sun, 14 May 2017 16:31:00 +0200 Subject: [PATCH] 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 a465b9e..e578a39 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