From f0b27c58267235732f663b9f9b6d4c9d16fc1840 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 21 Jan 2023 20:09:53 +0200 Subject: [PATCH] Enable implicit construction when the alternative is explicitly constructible from the argument. Fixes #103. --- include/boost/system/result.hpp | 4 ++-- test/result_error_construct.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/boost/system/result.hpp b/include/boost/system/result.hpp index fb2f9bd..33eec39 100644 --- a/include/boost/system/result.hpp +++ b/include/boost/system/result.hpp @@ -122,7 +122,7 @@ public: template::value && !(detail::is_errc_t::value && std::is_arithmetic::value) && - !std::is_constructible::value, int>::type = 0> + !std::is_convertible::value, int>::type = 0> constexpr result( A&& a ) noexcept( std::is_nothrow_constructible::value ) : v_( in_place_value, std::forward(a) ) @@ -132,7 +132,7 @@ public: // implicit, error template::value && - !std::is_constructible::value, int>::type = 0> + !std::is_convertible::value, int>::type = 0> constexpr result( A&& a ) noexcept( std::is_nothrow_constructible::value ) : v_( in_place_error, std::forward(a) ) diff --git a/test/result_error_construct.cpp b/test/result_error_construct.cpp index 8cee5a9..af9de73 100644 --- a/test/result_error_construct.cpp +++ b/test/result_error_construct.cpp @@ -146,8 +146,14 @@ int main() BOOST_TEST_TRAIT_TRUE((std::is_constructible, int>)); BOOST_TEST_TRAIT_FALSE((std::is_convertible>)); - BOOST_TEST_TRAIT_FALSE((std::is_constructible, int>)); - BOOST_TEST_TRAIT_FALSE((std::is_convertible>)); + // 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, int>)); + + BOOST_TEST_TRAIT_TRUE((std::is_convertible>)); } {