Skip to content

Commit

Permalink
Disable errc_t -> arithmetic conversions when initializing result (cl…
Browse files Browse the repository at this point in the history
…oses #74)
  • Loading branch information
pdimov committed Dec 10, 2021
1 parent 8c9ceba commit 01ce081
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/boost/system/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ constexpr in_place_value_t in_place_value{};
using in_place_error_t = variant2::in_place_index_t<1>;
constexpr in_place_error_t in_place_error{};

namespace detail
{

template<class T> using remove_cvref = typename std::remove_cv< typename std::remove_reference<T>::type >::type;

template<class... T> using is_errc_t = std::is_same<mp11::mp_list<remove_cvref<T>...>, mp11::mp_list<errc::errc_t>>;

} // namespace detail

// result

template<class T, class E = error_code> class result
Expand All @@ -65,6 +74,7 @@ template<class T, class E = error_code> class result
// implicit, value
template<class A = T, typename std::enable_if<
std::is_convertible<A, T>::value &&
!(detail::is_errc_t<A>::value && std::is_arithmetic<T>::value) &&
!std::is_constructible<E, A>::value, int>::type = 0>
constexpr result( A&& a )
noexcept( std::is_nothrow_constructible<T, A>::value )
Expand All @@ -85,6 +95,7 @@ template<class T, class E = error_code> class result
// explicit, value
template<class... A, class En = typename std::enable_if<
std::is_constructible<T, A...>::value &&
!(detail::is_errc_t<A...>::value && std::is_arithmetic<T>::value) &&
!std::is_constructible<E, A...>::value
>::type>
explicit constexpr result( A&&... a )
Expand Down

0 comments on commit 01ce081

Please sign in to comment.