From 52bbec06cfc8f89ee8aed49599f879c9a653b504 Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Tue, 16 Jan 2024 22:32:42 -0800 Subject: [PATCH] Minor changes in result member functions sfinae use --- include/boost/leaf/result.hpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/include/boost/leaf/result.hpp b/include/boost/leaf/result.hpp index b7817723..9e72880a 100644 --- a/include/boost/leaf/result.hpp +++ b/include/boost/leaf/result.hpp @@ -329,10 +329,19 @@ class BOOST_LEAF_SYMBOL_VISIBLE result } } + template + void move_assign( result && x ) noexcept + { + destroy(); + what_ = move_from(std::move(x)); + } + public: using value_type = T; + // NOTE: Copy constructor implicitly deleted. + result( result && x ) noexcept: what_(move_from(std::move(x))) { @@ -404,8 +413,8 @@ class BOOST_LEAF_SYMBOL_VISIBLE result { } - template - result( Enum e, typename std::enable_if::value, int>::type * = nullptr ) noexcept: + template ::value, int>::type> + result( Enum e ) noexcept: what_(error_id(e)) { } @@ -416,18 +425,18 @@ class BOOST_LEAF_SYMBOL_VISIBLE result destroy(); } + // NOTE: Assignment operator implicitly deleted. + result & operator=( result && x ) noexcept { - destroy(); - what_ = move_from(std::move(x)); + move_assign(std::move(x)); return *this; } - template + template ::value>::type> result & operator=( result && x ) noexcept { - destroy(); - what_ = move_from(std::move(x)); + move_assign(std::move(x)); return *this; } @@ -627,6 +636,7 @@ class BOOST_LEAF_SYMBOL_VISIBLE result: using value_type = void; + // NOTE: Copy constructor implicitly deleted. result( result && x ) noexcept: base(std::move(x)) { @@ -647,8 +657,8 @@ class BOOST_LEAF_SYMBOL_VISIBLE result: { } - template - result( Enum e, typename std::enable_if::value, Enum>::type * = nullptr ) noexcept: + template ::value, int>::type> + result( Enum e ) noexcept: base(e) { } @@ -658,6 +668,13 @@ class BOOST_LEAF_SYMBOL_VISIBLE result: { } + // NOTE: Assignment operator implicitly deleted. + result & operator=( result && x ) noexcept + { + base::move_assign(std::move(x)); + return *this; + } + void value() const { base::enforce_value_state();