mirror of
https://github.com/TartanLlama/expected.git
synced 2025-08-01 09:54:29 +02:00
Tidy traits
This commit is contained in:
@@ -237,10 +237,41 @@ template <class B, class... Bs>
|
|||||||
struct conjunction<B, Bs...>
|
struct conjunction<B, Bs...>
|
||||||
: std::conditional<bool(B::value), conjunction<Bs...>, B>::type {};
|
: std::conditional<bool(B::value), conjunction<Bs...>, B>::type {};
|
||||||
|
|
||||||
|
#if defined(_LIBCPP_VERSION) && __cplusplus == 201103L
|
||||||
|
#define TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// In C++11 mode, there's an issue in libc++'s std::mem_fn
|
||||||
|
// 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.
|
||||||
|
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
|
||||||
|
template <class T> struct is_pointer_to_non_const_member_func : std::false_type {};
|
||||||
|
template <class T, class Ret, class... Args>
|
||||||
|
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...)> : std::true_type {};
|
||||||
|
template <class T, class Ret, class... Args>
|
||||||
|
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...)&> : std::true_type {};
|
||||||
|
template <class T, class Ret, class... Args>
|
||||||
|
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) &&> : std::true_type {};
|
||||||
|
template <class T, class Ret, class... Args>
|
||||||
|
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile> : std::true_type {};
|
||||||
|
template <class T, class Ret, class... Args>
|
||||||
|
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile &> : std::true_type {};
|
||||||
|
template <class T, class Ret, class... Args>
|
||||||
|
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<T const&> : std::true_type {};
|
||||||
|
template <class T> struct is_const_or_const_ref<T const> : std::true_type {};
|
||||||
|
#endif
|
||||||
|
|
||||||
// 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,
|
||||||
typename = enable_if_t<std::is_member_pointer<decay_t<Fn>>{}>,
|
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
|
||||||
|
typename = enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value
|
||||||
|
&& is_const_or_const_ref<Args...>::value)>,
|
||||||
|
#endif
|
||||||
|
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)...)))
|
||||||
@@ -249,7 +280,7 @@ constexpr auto invoke(Fn &&f, Args &&... args) noexcept(
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Fn, typename... Args,
|
template <typename Fn, typename... Args,
|
||||||
typename = enable_if_t<!std::is_member_pointer<decay_t<Fn>>{}>>
|
typename = enable_if_t<!std::is_member_pointer<decay_t<Fn>>::value>>
|
||||||
constexpr auto invoke(Fn && f, Args && ... args) noexcept(
|
constexpr auto invoke(Fn && f, Args && ... args) noexcept(
|
||||||
noexcept(std::forward<Fn>(f)(std::forward<Args>(args)...)))
|
noexcept(std::forward<Fn>(f)(std::forward<Args>(args)...)))
|
||||||
-> decltype(std::forward<Fn>(f)(std::forward<Args>(args)...)) {
|
-> decltype(std::forward<Fn>(f)(std::forward<Args>(args)...)) {
|
||||||
@@ -2421,5 +2452,4 @@ void swap(expected<T, E> &lhs,
|
|||||||
}
|
}
|
||||||
} // namespace tl
|
} // namespace tl
|
||||||
|
|
||||||
#define TL_OPTIONAL_EXPECTED_MUTEX
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user