Skip to content

Commit

Permalink
feat: add SFINAE to result template ctor
Browse files Browse the repository at this point in the history
ToruNiina committed Jun 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f317cc0 commit 835d38a
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions include/toml11/result.hpp
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 835d38a

Please sign in to comment.