Skip to content

Commit

Permalink
Apply conditional noexcept to Expected's constructors. (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyONeal authored Oct 31, 2023
1 parent 59e38bf commit 4afdf87
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions include/vcpkg/base/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ namespace vcpkg
std::enable_if_t<std::is_convertible_v<ConvToT, T> &&
!std::is_same_v<std::remove_reference_t<ConvToT>, Error>,
int> = 0>
ExpectedT(ConvToT&& t) : m_t(std::forward<ConvToT>(t)), value_is_error(false)
ExpectedT(ConvToT&& t) noexcept(std::is_nothrow_constructible_v<T, ConvToT>)
: m_t(std::forward<ConvToT>(t)), value_is_error(false)
{
}

Expand All @@ -83,18 +84,21 @@ namespace vcpkg
!std::is_same_v<std::remove_reference_t<ConvToError>, T>,
int> = 0,
int = 1>
ExpectedT(ConvToError&& e) : m_error(std::forward<ConvToError>(e)), value_is_error(true)
ExpectedT(ConvToError&& e) noexcept(std::is_nothrow_constructible_v<Error, ConvToError>)
: m_error(std::forward<ConvToError>(e)), value_is_error(true)
{
}

// Constructors that explicitly specify left or right exist if the parameter is convertible to T or Error
template<class ConvToT, std::enable_if_t<std::is_convertible_v<ConvToT, T>, int> = 0>
ExpectedT(ConvToT&& t, ExpectedLeftTag) : m_t(std::forward<ConvToT>(t)), value_is_error(false)
ExpectedT(ConvToT&& t, ExpectedLeftTag) noexcept(std::is_nothrow_constructible_v<T, ConvToT>)
: m_t(std::forward<ConvToT>(t)), value_is_error(false)
{
}

template<class ConvToError, std::enable_if_t<std::is_convertible_v<ConvToError, Error>, int> = 0>
ExpectedT(ConvToError&& e, ExpectedRightTag) : m_error(std::forward<ConvToError>(e)), value_is_error(true)
ExpectedT(ConvToError&& e, ExpectedRightTag) noexcept(std::is_nothrow_constructible_v<Error, ConvToError>)
: m_error(std::forward<ConvToError>(e)), value_is_error(true)
{
}

Expand Down

0 comments on commit 4afdf87

Please sign in to comment.