mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 00:38:08 +08:00
feat: add SFINAE to result template ctor
This commit is contained in:
@@ -186,14 +186,16 @@ struct result
|
|||||||
result(success_type s): is_ok_(true), succ(std::move(s)) {}
|
result(success_type s): is_ok_(true), succ(std::move(s)) {}
|
||||||
result(failure_type f): is_ok_(false), fail(std::move(f)) {}
|
result(failure_type f): is_ok_(false), fail(std::move(f)) {}
|
||||||
|
|
||||||
template<typename U, cxx::enable_if_t<
|
template<typename U, cxx::enable_if_t<cxx::conjunction<
|
||||||
std::is_convertible<cxx::remove_cvref_t<U>, value_type>::value,
|
cxx::negation<std::is_same<cxx::remove_cvref_t<U>, value_type>>,
|
||||||
std::nullptr_t> = nullptr>
|
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)) {}
|
result(success<U> s): is_ok_(true), succ(std::move(s.value)) {}
|
||||||
|
|
||||||
template<typename U, cxx::enable_if_t<
|
template<typename U, cxx::enable_if_t<cxx::conjunction<
|
||||||
std::is_convertible<cxx::remove_cvref_t<U>, error_type>::value,
|
cxx::negation<std::is_same<cxx::remove_cvref_t<U>, error_type>>,
|
||||||
std::nullptr_t> = nullptr>
|
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(failure<U> f): is_ok_(false), fail(std::move(f.value)) {}
|
||||||
|
|
||||||
result& operator=(success_type s)
|
result& operator=(success_type s)
|
||||||
@@ -306,7 +308,12 @@ struct result
|
|||||||
return *this;
|
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())
|
result(result<U, F> other): is_ok_(other.is_ok())
|
||||||
{
|
{
|
||||||
if(other.is_ok())
|
if(other.is_ok())
|
||||||
@@ -322,7 +329,13 @@ struct result
|
|||||||
(void)tmp;
|
(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)
|
result& operator=(result<U, F> other)
|
||||||
{
|
{
|
||||||
this->cleanup();
|
this->cleanup();
|
||||||
|
Reference in New Issue
Block a user