Add a Result<T> converting constructor

This commit is contained in:
Jeremy Rifkin 2025-01-26 20:29:13 -06:00
parent 6a9d2c5bbd
commit 7a1eb4d5bf
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4

View File

@ -33,6 +33,16 @@ namespace detail {
std::fprintf(stderr, "%s\n", unwrap_error().what());
}
}
template<
typename U = T,
typename std::enable_if<
!std::is_same<typename std::decay<U>::type, Result<T, E>>::value &&
std::is_constructible<value_type, U>::value &&
!std::is_constructible<E, U>::value,
int
>::type = 0
>
Result(U&& u) : Result(value_type(std::forward<U>(u))) {}
Result(Result&& other) : active(other.active) {
if(other.active == member::value) {
new (&value_) value_type(std::move(other.value_));