mirror of
https://github.com/TartanLlama/expected.git
synced 2025-08-02 18:34:29 +02:00
@@ -66,30 +66,30 @@
|
|||||||
#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
|
#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
|
||||||
std::is_trivially_destructible<T>
|
std::is_trivially_destructible<T>
|
||||||
|
|
||||||
// GCC 5 < v < 8 has a bug in is_trivially_copy_constructible which breaks std::vector
|
// GCC 5 < v < 8 has a bug in is_trivially_copy_constructible which breaks
|
||||||
// for non-copyable types
|
// std::vector for non-copyable types
|
||||||
#elif (defined(__GNUC__) && __GNUC__ < 8 && \
|
#elif (defined(__GNUC__) && __GNUC__ < 8 && !defined(__clang__))
|
||||||
!defined(__clang__))
|
|
||||||
#ifndef TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
|
#ifndef TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
|
||||||
#define TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
|
#define TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
|
||||||
namespace tl {
|
namespace tl {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template <class T>
|
template <class T>
|
||||||
struct is_trivially_copy_constructible : std::is_trivially_copy_constructible<T>{};
|
struct is_trivially_copy_constructible
|
||||||
|
: std::is_trivially_copy_constructible<T> {};
|
||||||
#ifdef _GLIBCXX_VECTOR
|
#ifdef _GLIBCXX_VECTOR
|
||||||
template <class T, class A>
|
template <class T, class A>
|
||||||
struct is_trivially_copy_constructible<std::vector<T,A>>
|
struct is_trivially_copy_constructible<std::vector<T, A>> : std::false_type {};
|
||||||
: std::false_type{};
|
|
||||||
#endif
|
#endif
|
||||||
}
|
} // namespace detail
|
||||||
}
|
} // namespace tl
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
|
#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
|
||||||
tl::detail::is_trivially_copy_constructible<T>
|
tl::detail::is_trivially_copy_constructible<T>
|
||||||
#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
|
#define TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(T) \
|
||||||
std::is_trivially_copy_assignable<T>
|
std::is_trivially_copy_assignable<T>
|
||||||
#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) std::is_trivially_destructible<T>
|
#define TL_EXPECTED_IS_TRIVIALLY_DESTRUCTIBLE(T) \
|
||||||
|
std::is_trivially_destructible<T>
|
||||||
#else
|
#else
|
||||||
#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
|
#define TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(T) \
|
||||||
std::is_trivially_copy_constructible<T>
|
std::is_trivially_copy_constructible<T>
|
||||||
@@ -138,7 +138,6 @@ public:
|
|||||||
|
|
||||||
constexpr explicit unexpected(E &&e) : m_val(std::move(e)) {}
|
constexpr explicit unexpected(E &&e) : m_val(std::move(e)) {}
|
||||||
|
|
||||||
|
|
||||||
template <class... Args, typename std::enable_if<std::is_constructible<
|
template <class... Args, typename std::enable_if<std::is_constructible<
|
||||||
E, Args &&...>::value>::type * = nullptr>
|
E, Args &&...>::value>::type * = nullptr>
|
||||||
constexpr explicit unexpected(Args &&...args)
|
constexpr explicit unexpected(Args &&...args)
|
||||||
@@ -147,8 +146,7 @@ public:
|
|||||||
class U, class... Args,
|
class U, class... Args,
|
||||||
typename std::enable_if<std::is_constructible<
|
typename std::enable_if<std::is_constructible<
|
||||||
E, std::initializer_list<U> &, Args &&...>::value>::type * = nullptr>
|
E, std::initializer_list<U> &, Args &&...>::value>::type * = nullptr>
|
||||||
constexpr explicit unexpected(std::initializer_list<U> l,
|
constexpr explicit unexpected(std::initializer_list<U> l, Args &&...args)
|
||||||
Args &&...args)
|
|
||||||
: m_val(l, std::forward<Args>(args)...) {}
|
: m_val(l, std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
constexpr const E &value() const & { return m_val; }
|
constexpr const E &value() const & { return m_val; }
|
||||||
@@ -161,8 +159,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cpp_deduction_guides
|
#ifdef __cpp_deduction_guides
|
||||||
template<class E>
|
template <class E> unexpected(E) -> unexpected<E>;
|
||||||
unexpected(E) -> unexpected<E>;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <class E>
|
template <class E>
|
||||||
@@ -241,19 +238,26 @@ struct conjunction<B, Bs...>
|
|||||||
// which results in a hard-error when using it in a noexcept expression
|
// which results in a hard-error when using it in a noexcept expression
|
||||||
// in some cases. This is a check to workaround the common failing case.
|
// in some cases. This is a check to workaround the common failing case.
|
||||||
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
|
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
|
||||||
template <class T> struct is_pointer_to_non_const_member_func : std::false_type {};
|
template <class T>
|
||||||
|
struct is_pointer_to_non_const_member_func : std::false_type {};
|
||||||
template <class T, class Ret, class... Args>
|
template <class T, class Ret, class... Args>
|
||||||
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...)> : std::true_type {};
|
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...)>
|
||||||
|
: std::true_type {};
|
||||||
template <class T, class Ret, class... Args>
|
template <class T, class Ret, class... Args>
|
||||||
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...)&> : std::true_type {};
|
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &>
|
||||||
|
: std::true_type {};
|
||||||
template <class T, class Ret, class... Args>
|
template <class T, class Ret, class... Args>
|
||||||
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) &&> : std::true_type {};
|
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &&>
|
||||||
|
: std::true_type {};
|
||||||
template <class T, class Ret, class... Args>
|
template <class T, class Ret, class... Args>
|
||||||
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile> : std::true_type {};
|
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile>
|
||||||
|
: std::true_type {};
|
||||||
template <class T, class Ret, class... Args>
|
template <class T, class Ret, class... Args>
|
||||||
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile &> : std::true_type {};
|
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile &>
|
||||||
|
: std::true_type {};
|
||||||
template <class T, class Ret, class... Args>
|
template <class T, class Ret, class... Args>
|
||||||
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile &&> : std::true_type {};
|
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile &&>
|
||||||
|
: std::true_type {};
|
||||||
|
|
||||||
template <class T> struct is_const_or_const_ref : std::false_type {};
|
template <class T> struct is_const_or_const_ref : std::false_type {};
|
||||||
template <class T> struct is_const_or_const_ref<T const &> : std::true_type {};
|
template <class T> struct is_const_or_const_ref<T const &> : std::true_type {};
|
||||||
@@ -262,13 +266,13 @@ template <class T> struct is_const_or_const_ref<T const> : std::true_type {};
|
|||||||
|
|
||||||
// std::invoke from C++17
|
// std::invoke from C++17
|
||||||
// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround
|
// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround
|
||||||
template <typename Fn, typename... Args,
|
template <
|
||||||
|
typename Fn, typename... Args,
|
||||||
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
|
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
|
||||||
typename = enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value
|
typename = enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value &&
|
||||||
&& is_const_or_const_ref<Args...>::value)>,
|
is_const_or_const_ref<Args...>::value)>,
|
||||||
#endif
|
#endif
|
||||||
typename = enable_if_t<std::is_member_pointer<decay_t<Fn>>::value>,
|
typename = enable_if_t<std::is_member_pointer<decay_t<Fn>>::value>, int = 0>
|
||||||
int = 0>
|
|
||||||
constexpr auto invoke(Fn &&f, Args &&...args) noexcept(
|
constexpr auto invoke(Fn &&f, Args &&...args) noexcept(
|
||||||
noexcept(std::mem_fn(f)(std::forward<Args>(args)...)))
|
noexcept(std::mem_fn(f)(std::forward<Args>(args)...)))
|
||||||
-> decltype(std::mem_fn(f)(std::forward<Args>(args)...)) {
|
-> decltype(std::mem_fn(f)(std::forward<Args>(args)...)) {
|
||||||
@@ -288,9 +292,11 @@ template <class F, class, class... Us> struct invoke_result_impl;
|
|||||||
|
|
||||||
template <class F, class... Us>
|
template <class F, class... Us>
|
||||||
struct invoke_result_impl<
|
struct invoke_result_impl<
|
||||||
F, decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...), void()),
|
F,
|
||||||
|
decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...), void()),
|
||||||
Us...> {
|
Us...> {
|
||||||
using type = decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...));
|
using type =
|
||||||
|
decltype(detail::invoke(std::declval<F>(), std::declval<Us>()...));
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class F, class... Us>
|
template <class F, class... Us>
|
||||||
@@ -355,8 +361,8 @@ struct is_swappable<T[N], T[N]>
|
|||||||
: std::integral_constant<
|
: std::integral_constant<
|
||||||
bool,
|
bool,
|
||||||
decltype(detail::swap_adl_tests::can_swap<T[N], T[N]>(0))::value &&
|
decltype(detail::swap_adl_tests::can_swap<T[N], T[N]>(0))::value &&
|
||||||
(!decltype(
|
(!decltype(detail::swap_adl_tests::uses_std<T[N], T[N]>(
|
||||||
detail::swap_adl_tests::uses_std<T[N], T[N]>(0))::value ||
|
0))::value ||
|
||||||
is_swappable<T, T>::value)> {};
|
is_swappable<T, T>::value)> {};
|
||||||
|
|
||||||
template <class T, class U = T>
|
template <class T, class U = T>
|
||||||
@@ -364,12 +370,10 @@ struct is_nothrow_swappable
|
|||||||
: std::integral_constant<
|
: std::integral_constant<
|
||||||
bool,
|
bool,
|
||||||
is_swappable<T, U>::value &&
|
is_swappable<T, U>::value &&
|
||||||
((decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value
|
((decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value &&
|
||||||
&& detail::swap_adl_tests::is_std_swap_noexcept<T>::value) ||
|
detail::swap_adl_tests::is_std_swap_noexcept<T>::value) ||
|
||||||
(!decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value &&
|
(!decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value &&
|
||||||
detail::swap_adl_tests::is_adl_swap_noexcept<T,
|
detail::swap_adl_tests::is_adl_swap_noexcept<T, U>::value))> {};
|
||||||
U>::value))> {
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -411,14 +415,10 @@ using is_move_constructible_or_void =
|
|||||||
is_void_or<T, std::is_move_constructible<T>>;
|
is_void_or<T, std::is_move_constructible<T>>;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
using is_copy_assignable_or_void =
|
using is_copy_assignable_or_void = is_void_or<T, std::is_copy_assignable<T>>;
|
||||||
is_void_or<T, std::is_copy_assignable<T>>;
|
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
using is_move_assignable_or_void =
|
using is_move_assignable_or_void = is_void_or<T, std::is_move_assignable<T>>;
|
||||||
is_void_or<T, std::is_move_assignable<T>>;
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
@@ -857,9 +857,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TL_EXPECTED_11_CONSTEXPR void destroy_val() {
|
TL_EXPECTED_11_CONSTEXPR void destroy_val() { get().~T(); }
|
||||||
get().~T();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// This base class provides some handy member functions which can be used in
|
// This base class provides some handy member functions which can be used in
|
||||||
@@ -1238,14 +1236,17 @@ class expected : private detail::expected_move_assign_base<T, E>,
|
|||||||
"T must not be in_place_t");
|
"T must not be in_place_t");
|
||||||
static_assert(!std::is_same<T, std::remove_cv<unexpect_t>::type>::value,
|
static_assert(!std::is_same<T, std::remove_cv<unexpect_t>::type>::value,
|
||||||
"T must not be unexpect_t");
|
"T must not be unexpect_t");
|
||||||
static_assert(!std::is_same<T, typename std::remove_cv<unexpected<E>>::type>::value,
|
static_assert(
|
||||||
|
!std::is_same<T, typename std::remove_cv<unexpected<E>>::type>::value,
|
||||||
"T must not be unexpected<E>");
|
"T must not be unexpected<E>");
|
||||||
static_assert(!std::is_reference<E>::value, "E must not be a reference");
|
static_assert(!std::is_reference<E>::value, "E must not be a reference");
|
||||||
|
|
||||||
T *valptr() { return std::addressof(this->m_val); }
|
T *valptr() { return std::addressof(this->m_val); }
|
||||||
const T *valptr() const { return std::addressof(this->m_val); }
|
const T *valptr() const { return std::addressof(this->m_val); }
|
||||||
unexpected<E> *errptr() { return std::addressof(this->m_unexpect); }
|
unexpected<E> *errptr() { return std::addressof(this->m_unexpect); }
|
||||||
const unexpected<E> *errptr() const { return std::addressof(this->m_unexpect); }
|
const unexpected<E> *errptr() const {
|
||||||
|
return std::addressof(this->m_unexpect);
|
||||||
|
}
|
||||||
|
|
||||||
template <class U = T,
|
template <class U = T,
|
||||||
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
|
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
|
||||||
@@ -1290,24 +1291,26 @@ public:
|
|||||||
#else
|
#else
|
||||||
template <class F>
|
template <class F>
|
||||||
TL_EXPECTED_11_CONSTEXPR auto
|
TL_EXPECTED_11_CONSTEXPR auto
|
||||||
and_then(F &&f) & -> decltype(and_then_impl(std::declval<expected&>(), std::forward<F>(f))) {
|
and_then(F &&f) & -> decltype(and_then_impl(std::declval<expected &>(),
|
||||||
|
std::forward<F>(f))) {
|
||||||
return and_then_impl(*this, std::forward<F>(f));
|
return and_then_impl(*this, std::forward<F>(f));
|
||||||
}
|
}
|
||||||
template <class F>
|
template <class F>
|
||||||
TL_EXPECTED_11_CONSTEXPR auto and_then(F &&f) && -> decltype(
|
TL_EXPECTED_11_CONSTEXPR auto
|
||||||
and_then_impl(std::declval<expected&&>(), std::forward<F>(f))) {
|
and_then(F &&f) && -> decltype(and_then_impl(std::declval<expected &&>(),
|
||||||
|
std::forward<F>(f))) {
|
||||||
return and_then_impl(std::move(*this), std::forward<F>(f));
|
return and_then_impl(std::move(*this), std::forward<F>(f));
|
||||||
}
|
}
|
||||||
template <class F>
|
template <class F>
|
||||||
constexpr auto and_then(F &&f) const & -> decltype(
|
constexpr auto and_then(F &&f) const & -> decltype(and_then_impl(
|
||||||
and_then_impl(std::declval<expected const&>(), std::forward<F>(f))) {
|
std::declval<expected const &>(), std::forward<F>(f))) {
|
||||||
return and_then_impl(*this, std::forward<F>(f));
|
return and_then_impl(*this, std::forward<F>(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TL_EXPECTED_NO_CONSTRR
|
#ifndef TL_EXPECTED_NO_CONSTRR
|
||||||
template <class F>
|
template <class F>
|
||||||
constexpr auto and_then(F &&f) const && -> decltype(
|
constexpr auto and_then(F &&f) const && -> decltype(and_then_impl(
|
||||||
and_then_impl(std::declval<expected const&&>(), std::forward<F>(f))) {
|
std::declval<expected const &&>(), std::forward<F>(f))) {
|
||||||
return and_then_impl(std::move(*this), std::forward<F>(f));
|
return and_then_impl(std::move(*this), std::forward<F>(f));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1329,14 +1332,14 @@ public:
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
template <class F>
|
template <class F>
|
||||||
TL_EXPECTED_11_CONSTEXPR decltype(
|
TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(
|
||||||
expected_map_impl(std::declval<expected &>(), std::declval<F &&>()))
|
std::declval<expected &>(), std::declval<F &&>()))
|
||||||
map(F &&f) & {
|
map(F &&f) & {
|
||||||
return expected_map_impl(*this, std::forward<F>(f));
|
return expected_map_impl(*this, std::forward<F>(f));
|
||||||
}
|
}
|
||||||
template <class F>
|
template <class F>
|
||||||
TL_EXPECTED_11_CONSTEXPR decltype(
|
TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval<expected>(),
|
||||||
expected_map_impl(std::declval<expected>(), std::declval<F &&>()))
|
std::declval<F &&>()))
|
||||||
map(F &&f) && {
|
map(F &&f) && {
|
||||||
return expected_map_impl(std::move(*this), std::forward<F>(f));
|
return expected_map_impl(std::move(*this), std::forward<F>(f));
|
||||||
}
|
}
|
||||||
@@ -1373,14 +1376,14 @@ public:
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
template <class F>
|
template <class F>
|
||||||
TL_EXPECTED_11_CONSTEXPR decltype(
|
TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(
|
||||||
expected_map_impl(std::declval<expected &>(), std::declval<F &&>()))
|
std::declval<expected &>(), std::declval<F &&>()))
|
||||||
transform(F &&f) & {
|
transform(F &&f) & {
|
||||||
return expected_map_impl(*this, std::forward<F>(f));
|
return expected_map_impl(*this, std::forward<F>(f));
|
||||||
}
|
}
|
||||||
template <class F>
|
template <class F>
|
||||||
TL_EXPECTED_11_CONSTEXPR decltype(
|
TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval<expected>(),
|
||||||
expected_map_impl(std::declval<expected>(), std::declval<F &&>()))
|
std::declval<F &&>()))
|
||||||
transform(F &&f) && {
|
transform(F &&f) && {
|
||||||
return expected_map_impl(std::move(*this), std::forward<F>(f));
|
return expected_map_impl(std::move(*this), std::forward<F>(f));
|
||||||
}
|
}
|
||||||
@@ -2241,9 +2244,9 @@ template <class Exp, class F,
|
|||||||
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
|
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
|
||||||
constexpr auto or_else_impl(Exp &&exp, F &&f) {
|
constexpr auto or_else_impl(Exp &&exp, F &&f) {
|
||||||
static_assert(detail::is_expected<Ret>::value, "F must return an expected");
|
static_assert(detail::is_expected<Ret>::value, "F must return an expected");
|
||||||
return exp.has_value()
|
return exp.has_value() ? std::forward<Exp>(exp)
|
||||||
? std::forward<Exp>(exp)
|
: detail::invoke(std::forward<F>(f),
|
||||||
: detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
|
std::forward<Exp>(exp).error());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Exp, class F,
|
template <class Exp, class F,
|
||||||
@@ -2251,9 +2254,9 @@ template <class Exp, class F,
|
|||||||
std::declval<Exp>().error())),
|
std::declval<Exp>().error())),
|
||||||
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
|
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
|
||||||
detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) {
|
detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) {
|
||||||
return exp.has_value()
|
return exp.has_value() ? std::forward<Exp>(exp)
|
||||||
? std::forward<Exp>(exp)
|
: (detail::invoke(std::forward<F>(f),
|
||||||
: (detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error()),
|
std::forward<Exp>(exp).error()),
|
||||||
std::forward<Exp>(exp));
|
std::forward<Exp>(exp));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -2263,9 +2266,9 @@ template <class Exp, class F,
|
|||||||
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
|
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
|
||||||
auto or_else_impl(Exp &&exp, F &&f) -> Ret {
|
auto or_else_impl(Exp &&exp, F &&f) -> Ret {
|
||||||
static_assert(detail::is_expected<Ret>::value, "F must return an expected");
|
static_assert(detail::is_expected<Ret>::value, "F must return an expected");
|
||||||
return exp.has_value()
|
return exp.has_value() ? std::forward<Exp>(exp)
|
||||||
? std::forward<Exp>(exp)
|
: detail::invoke(std::forward<F>(f),
|
||||||
: detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
|
std::forward<Exp>(exp).error());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Exp, class F,
|
template <class Exp, class F,
|
||||||
@@ -2273,9 +2276,9 @@ template <class Exp, class F,
|
|||||||
std::declval<Exp>().error())),
|
std::declval<Exp>().error())),
|
||||||
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
|
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
|
||||||
detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) {
|
detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) {
|
||||||
return exp.has_value()
|
return exp.has_value() ? std::forward<Exp>(exp)
|
||||||
? std::forward<Exp>(exp)
|
: (detail::invoke(std::forward<F>(f),
|
||||||
: (detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error()),
|
std::forward<Exp>(exp).error()),
|
||||||
std::forward<Exp>(exp));
|
std::forward<Exp>(exp));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user