From d8bf33a544397a2afd04dec3838871518f0fc1b6 Mon Sep 17 00:00:00 2001 From: ngrodzitski Date: Tue, 7 Aug 2018 11:57:30 +0300 Subject: [PATCH] Make some rvalue qualified function to reuse lvalue versions of corresponding functions. --- include/nonstd/optional.hpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/include/nonstd/optional.hpp b/include/nonstd/optional.hpp index 875c324..34b0e8d 100644 --- a/include/nonstd/optional.hpp +++ b/include/nonstd/optional.hpp @@ -579,12 +579,12 @@ union storage_t value_type const && value() const optional_refref_qual { - return * value_ptr(); + return std::move( value() ); } value_type && value() optional_refref_qual { - return * value_ptr(); + return std::move( value() ); } #endif @@ -829,14 +829,12 @@ class optional optional_constexpr value_type const && operator *() const optional_refref_qual { - return assert( has_value() ), - std::move( contained.value() ); + return std::move( **this ); } optional_constexpr14 value_type && operator *() optional_refref_qual { - return assert( has_value() ), - std::move( contained.value() ); + return std::move( **this ); } #endif @@ -878,18 +876,12 @@ class optional optional_constexpr14 value_type const && value() const optional_refref_qual { - if ( ! has_value() ) - throw bad_optional_access(); - - return std::move( contained.value() ); + return std::move( value() ); } optional_constexpr14 value_type && value() optional_refref_qual { - if ( ! has_value() ) - throw bad_optional_access(); - - return std::move( contained.value() ); + return std::move( value() ); } #endif