feat: add SFINAE to result template ctor

This commit is contained in:
ToruNiina 2024-06-17 00:21:11 +09:00
parent f317cc0448
commit 835d38a22b

View File

@ -186,14 +186,16 @@ struct result
result(success_type s): is_ok_(true), succ(std::move(s)) {}
result(failure_type f): is_ok_(false), fail(std::move(f)) {}
template<typename U, cxx::enable_if_t<
std::is_convertible<cxx::remove_cvref_t<U>, value_type>::value,
std::nullptr_t> = nullptr>
template<typename U, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<U>, value_type>>,
std::is_convertible<cxx::remove_cvref_t<U>, value_type>
>::value, std::nullptr_t> = nullptr>
result(success<U> s): is_ok_(true), succ(std::move(s.value)) {}
template<typename U, cxx::enable_if_t<
std::is_convertible<cxx::remove_cvref_t<U>, error_type>::value,
std::nullptr_t> = nullptr>
template<typename U, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<U>, error_type>>,
std::is_convertible<cxx::remove_cvref_t<U>, error_type>
>::value, std::nullptr_t> = nullptr>
result(failure<U> f): is_ok_(false), fail(std::move(f.value)) {}
result& operator=(success_type s)
@ -306,7 +308,12 @@ struct result
return *this;
}
template<typename U, typename F>
template<typename U, typename F, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<U>, value_type>>,
cxx::negation<std::is_same<cxx::remove_cvref_t<F>, error_type>>,
std::is_convertible<cxx::remove_cvref_t<U>, value_type>,
std::is_convertible<cxx::remove_cvref_t<F>, error_type>
>::value, std::nullptr_t> = nullptr>
result(result<U, F> other): is_ok_(other.is_ok())
{
if(other.is_ok())
@ -322,7 +329,13 @@ struct result
(void)tmp;
}
}
template<typename U, typename F>
template<typename U, typename F, cxx::enable_if_t<cxx::conjunction<
cxx::negation<std::is_same<cxx::remove_cvref_t<U>, value_type>>,
cxx::negation<std::is_same<cxx::remove_cvref_t<F>, error_type>>,
std::is_convertible<cxx::remove_cvref_t<U>, value_type>,
std::is_convertible<cxx::remove_cvref_t<F>, error_type>
>::value, std::nullptr_t> = nullptr>
result& operator=(result<U, F> other)
{
this->cleanup();