From c4977866bc400971b7fa6f0ec08a29e1b4e80fda Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Sun, 5 Nov 2023 13:53:17 -0800 Subject: [PATCH] Public result::value_type --- include/boost/leaf/result.hpp | 32 +++++++++++++++++--------------- test/result_state_test.cpp | 6 ++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/include/boost/leaf/result.hpp b/include/boost/leaf/result.hpp index 7236ff38..7737f600 100644 --- a/include/boost/leaf/result.hpp +++ b/include/boost/leaf/result.hpp @@ -75,19 +75,19 @@ namespace leaf_detail struct stored { using type = T; - using value_type = T; - using value_type_const = T const; + using value_no_ref = T; + using value_no_ref_const = T const; using value_cref = T const &; using value_ref = T &; using value_rv_cref = T const &&; using value_rv_ref = T &&; - static value_type_const * cptr( type const & v ) noexcept + static value_no_ref_const * cptr( type const & v ) noexcept { return &v; } - static value_type * ptr( type & v ) noexcept + static value_no_ref * ptr( type & v ) noexcept { return &v; } @@ -97,19 +97,19 @@ namespace leaf_detail struct stored { using type = std::reference_wrapper; - using value_type_const = T; - using value_type = T; + using value_no_ref = T; + using value_no_ref_const = T; using value_ref = T &; using value_cref = T &; using value_rv_ref = T &; using value_rv_cref = T &; - static value_type_const * cptr( type const & v ) noexcept + static value_no_ref_const * cptr( type const & v ) noexcept { return &v.get(); } - static value_type * ptr( type const & v ) noexcept + static value_no_ref * ptr( type const & v ) noexcept { return &v.get(); } @@ -226,8 +226,8 @@ class BOOST_LEAF_NODISCARD result }; using stored_type = typename leaf_detail::stored::type; - using value_type = typename leaf_detail::stored::value_type; - using value_type_const = typename leaf_detail::stored::value_type_const; + using value_no_ref = typename leaf_detail::stored::value_no_ref; + using value_no_ref_const = typename leaf_detail::stored::value_no_ref_const; using value_ref = typename leaf_detail::stored::value_ref; using value_cref = typename leaf_detail::stored::value_cref; using value_rv_ref = typename leaf_detail::stored::value_rv_ref; @@ -330,6 +330,8 @@ class BOOST_LEAF_NODISCARD result public: + using value_type = T; + result( result && x ) noexcept: what_(move_from(std::move(x))) { @@ -347,13 +349,13 @@ class BOOST_LEAF_NODISCARD result { } - result( value_type && v ) noexcept: - stored_(std::forward(v)), + result( value_no_ref && v ) noexcept: + stored_(std::forward(v)), what_(result_discriminant::kind_val{}) { } - result( value_type const & v ): + result( value_no_ref const & v ): stored_(v), what_(result_discriminant::kind_val{}) { @@ -501,12 +503,12 @@ class BOOST_LEAF_NODISCARD result #endif - value_type_const * operator->() const noexcept + value_no_ref_const * operator->() const noexcept { return has_value() ? leaf_detail::stored::cptr(stored_) : nullptr; } - value_type * operator->() noexcept + value_no_ref * operator->() noexcept { return has_value() ? leaf_detail::stored::ptr(stored_) : nullptr; } diff --git a/test/result_state_test.cpp b/test/result_state_test.cpp index 8588afbc..fde52c3e 100644 --- a/test/result_state_test.cpp +++ b/test/result_state_test.cpp @@ -15,6 +15,12 @@ namespace leaf = boost::leaf; +static_assert(std::is_same::value_type>::value, "Bad value_type"); +static_assert(std::is_same::value_type>::value, "Bad value_type"); +static_assert(std::is_same::value_type>::value, "Bad value_type"); +static_assert(std::is_same::value_type>::value, "Bad value_type"); +static_assert(std::is_same::value_type>::value, "Bad value_type"); + struct val { static int id_count;