Skip to content

Commit

Permalink
Minor changes in result member functions sfinae use
Browse files Browse the repository at this point in the history
  • Loading branch information
zajo committed Jan 17, 2024
1 parent 66deb97 commit 52bbec0
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions include/boost/leaf/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,19 @@ class BOOST_LEAF_SYMBOL_VISIBLE result
}
}

template <class U>
void move_assign( result<U> && 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)))
{
Expand Down Expand Up @@ -404,8 +413,8 @@ class BOOST_LEAF_SYMBOL_VISIBLE result
{
}

template <class Enum>
result( Enum e, typename std::enable_if<std::is_error_code_enum<Enum>::value, int>::type * = nullptr ) noexcept:
template <class Enum, class = typename std::enable_if<std::is_error_code_enum<Enum>::value, int>::type>
result( Enum e ) noexcept:
what_(error_id(e))
{
}
Expand All @@ -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 <class U>
template <class U, class = typename std::enable_if<std::is_convertible<U, T>::value>::type>
result & operator=( result<U> && x ) noexcept
{
destroy();
what_ = move_from(std::move(x));
move_assign(std::move(x));
return *this;
}

Expand Down Expand Up @@ -627,6 +636,7 @@ class BOOST_LEAF_SYMBOL_VISIBLE result<void>:

using value_type = void;

// NOTE: Copy constructor implicitly deleted.
result( result && x ) noexcept:
base(std::move(x))
{
Expand All @@ -647,8 +657,8 @@ class BOOST_LEAF_SYMBOL_VISIBLE result<void>:
{
}

template <class Enum>
result( Enum e, typename std::enable_if<std::is_error_code_enum<Enum>::value, Enum>::type * = nullptr ) noexcept:
template <class Enum, class = typename std::enable_if<std::is_error_code_enum<Enum>::value, int>::type>
result( Enum e ) noexcept:
base(e)
{
}
Expand All @@ -658,6 +668,13 @@ class BOOST_LEAF_SYMBOL_VISIBLE result<void>:
{
}

// 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();
Expand Down

0 comments on commit 52bbec0

Please sign in to comment.