forked from boostorg/system
Enable implicit construction when the alternative is explicitly constructible from the argument. Fixes #103.
This commit is contained in:
@ -122,7 +122,7 @@ public:
|
||||
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>
|
||||
!std::is_convertible<A, E>::value, int>::type = 0>
|
||||
constexpr result( A&& a )
|
||||
noexcept( std::is_nothrow_constructible<T, A>::value )
|
||||
: v_( in_place_value, std::forward<A>(a) )
|
||||
@ -132,7 +132,7 @@ public:
|
||||
// implicit, error
|
||||
template<class A = E, class = void, typename std::enable_if<
|
||||
std::is_convertible<A, E>::value &&
|
||||
!std::is_constructible<T, A>::value, int>::type = 0>
|
||||
!std::is_convertible<A, T>::value, int>::type = 0>
|
||||
constexpr result( A&& a )
|
||||
noexcept( std::is_nothrow_constructible<E, A>::value )
|
||||
: v_( in_place_error, std::forward<A>(a) )
|
||||
|
@ -146,8 +146,14 @@ int main()
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<std::string, X>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<std::string, X>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, X>, int>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<int, X>>));
|
||||
// We'd like this to be false due to the ambiguity caused by X having
|
||||
// an explicit constructor taking an int, which should be viable in this
|
||||
// context, but the implicit constructor is enabled, and there's no way to
|
||||
// disallow it
|
||||
//
|
||||
// BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, X>, int>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_convertible<int, result<int, X>>));
|
||||
}
|
||||
|
||||
{
|
||||
|
Reference in New Issue
Block a user