From 3a792d1a18d73a3c711541f46d918c632a2bcdba Mon Sep 17 00:00:00 2001 From: Lakshay Garg Date: Thu, 5 Jul 2018 22:27:04 -0700 Subject: [PATCH] Add rvalue ref overload for get() Closes #51 --- include/boost/optional/optional.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index ff39dad9..113b84f2 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -1197,8 +1197,14 @@ class optional // Returns a reference to the value if this is initialized, otherwise, // the behaviour is UNDEFINED // No-throw +#if (!defined BOOST_NO_CXX11_REF_QUALIFIERS) && (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) + reference_const_type get() const& { BOOST_ASSERT(this->is_initialized()) ; return this->get_impl(); } + reference_type get() & { BOOST_ASSERT(this->is_initialized()) ; return this->get_impl(); } + reference_type_of_temporary_wrapper get() && { BOOST_ASSERT(this->is_initialized()) ; return boost::move(this->get_impl()); } +#else reference_const_type get() const { BOOST_ASSERT(this->is_initialized()) ; return this->get_impl(); } reference_type get() { BOOST_ASSERT(this->is_initialized()) ; return this->get_impl(); } +#endif // !defined BOOST_NO_CXX11_REF_QUALIFIERS // Returns a copy of the value if this is initialized, 'v' otherwise reference_const_type get_value_or ( reference_const_type v ) const { return this->is_initialized() ? get() : v ; }