mirror of
https://github.com/boostorg/system.git
synced 2025-07-30 04:27:14 +02:00
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<
|
template<class A = T, typename std::enable_if<
|
||||||
std::is_convertible<A, T>::value &&
|
std::is_convertible<A, T>::value &&
|
||||||
!(detail::is_errc_t<A>::value && std::is_arithmetic<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 )
|
constexpr result( A&& a )
|
||||||
noexcept( std::is_nothrow_constructible<T, A>::value )
|
noexcept( std::is_nothrow_constructible<T, A>::value )
|
||||||
: v_( in_place_value, std::forward<A>(a) )
|
: v_( in_place_value, std::forward<A>(a) )
|
||||||
@ -132,7 +132,7 @@ public:
|
|||||||
// implicit, error
|
// implicit, error
|
||||||
template<class A = E, class = void, typename std::enable_if<
|
template<class A = E, class = void, typename std::enable_if<
|
||||||
std::is_convertible<A, E>::value &&
|
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 )
|
constexpr result( A&& a )
|
||||||
noexcept( std::is_nothrow_constructible<E, A>::value )
|
noexcept( std::is_nothrow_constructible<E, A>::value )
|
||||||
: v_( in_place_error, std::forward<A>(a) )
|
: 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_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_convertible<int, result<std::string, X>>));
|
||||||
|
|
||||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, X>, int>));
|
// We'd like this to be false due to the ambiguity caused by X having
|
||||||
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<int, X>>));
|
// 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