15 #ifndef GUL14_TRAITS_H_
16 #define GUL14_TRAITS_H_
19 #include <type_traits>
46 template <
typename T,
typename =
int>
51 typename std::enable_if_t<true,
52 decltype(std::declval<T>().cbegin(),
53 std::declval<T>().cend(),
54 std::declval<typename T::value_type>(),
69 using remove_cvref =
typename std::remove_cv<std::remove_reference_t<T>>;
91 template <
typename...>
98 #if __cplusplus >= 201703L
108 namespace detail_invoke {
110 #define GUL14_INVOKE_RETURN(...) \
111 noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) { return __VA_ARGS__; }
113 template <
typename T>
114 struct is_reference_wrapper : std::false_type {};
116 template <
typename T>
117 struct is_reference_wrapper<std::reference_wrapper<T>>
124 struct Invoke<true , 0 > {
125 template <
typename R,
typename T,
typename Arg,
typename... Args>
126 inline static constexpr
auto invoke(R T::*pmf, Arg &&arg, Args &&... args)
127 GUL14_INVOKE_RETURN((std::forward<Arg>(arg).*pmf)(std::forward<Args>(args)...))
131 struct Invoke<true , 1 > {
132 template <
typename R,
typename T,
typename Arg,
typename... Args>
133 inline static constexpr
auto invoke(R T::*pmf, Arg &&arg, Args &&... args)
134 GUL14_INVOKE_RETURN((std::forward<Arg>(arg).
get().*pmf)(std::forward<Args>(args)...))
138 struct Invoke<true , 2 > {
139 template <
typename R,
typename T,
typename Arg,
typename... Args>
140 inline static constexpr
auto invoke(R T::*pmf, Arg &&arg, Args &&... args)
141 GUL14_INVOKE_RETURN(((*std::forward<Arg>(arg)).*pmf)(std::forward<Args>(args)...))
145 struct Invoke<false , 0 > {
146 template <
typename R,
typename T,
typename Arg>
147 inline static constexpr
auto invoke(R T::*pmo, Arg &&arg)
148 GUL14_INVOKE_RETURN(std::forward<Arg>(arg).*pmo)
152 struct Invoke<false , 1 > {
153 template <
typename R,
typename T,
typename Arg>
154 inline static constexpr
auto invoke(R T::*pmo, Arg &&arg)
155 GUL14_INVOKE_RETURN(std::forward<Arg>(arg).
get().*pmo)
159 struct Invoke<false , 2 > {
160 template <
typename R,
typename T,
typename Arg>
161 inline static constexpr
auto invoke(R T::*pmo, Arg &&arg)
162 GUL14_INVOKE_RETURN((*std::forward<Arg>(arg)).*pmo)
165 template <
typename R,
typename T,
typename Arg,
typename... Args>
166 inline constexpr
auto invoke(R T::*f, Arg&& arg, Args&&... args)
168 Invoke<std::is_function<R>::value,
169 (std::is_base_of<T, std::decay_t<Arg>>::value
171 : is_reference_wrapper<std::decay_t<Arg>>::value
173 : 2)>::
invoke(f, std::forward<Arg>(arg),
174 std::forward<Args>(args)...))
177 #pragma warning(push)
178 #pragma warning(disable : 4100)
180 template <
typename F,
typename... Args>
181 inline constexpr
auto invoke(F &&f, Args &&... args)
182 GUL14_INVOKE_RETURN(std::forward<F>(f)(std::forward<Args>(args)...))
187 #undef GUL14_INVOKE_RETURN
199 template <
typename F,
typename... Args>
200 inline constexpr
auto
209 namespace detail_invoke_result {
211 template <
typename T>
212 struct identity {
using type = T; };
214 template <
typename Void,
typename,
typename...>
217 template <
typename F,
typename... Args>
219 std::declval<F>(), std::declval<Args>()...))>,
223 invoke(std::declval<F>(), std::declval<Args>()...))> {};
236 template <
typename F,
typename... Args>
247 template <
typename F,
typename... Args>
251 namespace detail_invocable {
253 template <
typename Void,
typename,
typename...>
256 template <
typename F,
typename... Args>
260 template <
typename Void,
typename,
typename,
typename...>
263 template <
typename R,
typename F,
typename... Args>
268 : std::is_convertible<invoke_result_t<F, Args...>, R> {};
281 template <
typename F,
typename... Args>
294 template <
typename R,
typename F,
typename... Args>
constexpr auto get(span< E, S > s) -> decltype(s[N])
Return a reference to the Nth element of a given span.
Definition: span.h:544
typename remove_cvref< T >::type remove_cvref_t
A template metafunction that removes const, volatile, and reference qualifiers from a type.
Definition: traits.h:81
typename invoke_result< F, Args... >::type invoke_result_t
A shortcut for invoke_result<...>::type.
Definition: traits.h:248
detail_invoke_result::invoke_result< void, F, Args... > invoke_result
A metafunction that computes the result of invoking a callable object of type F with the given argume...
Definition: traits.h:237
constexpr auto invoke(F &&f, Args &&... args) noexcept(noexcept(detail_invoke::invoke(std::forward< F >(f), std::forward< Args >(args)...))) -> decltype(detail_invoke::invoke(std::forward< F >(f), std::forward< Args >(args)...))
Invoke a callable object f with the given arguments.
Definition: traits.h:201
void void_t
A type mapping an arbitrary list of types to void (for SFINAE).
Definition: traits.h:92
typename std::remove_cv< std::remove_reference_t< T > > remove_cvref
A template metafunction that removes const, volatile, and reference qualifiers from a type.
Definition: traits.h:69
detail_invocable::is_invocable< void, F, Args... > is_invocable
A type trait that checks whether a callable object of type F can be invoked with the given arguments.
Definition: traits.h:282
detail_invocable::is_invocable_r< void, R, F, Args... > is_invocable_r
A type trait that checks whether a callable object of type F can be invoked with the given arguments ...
Definition: traits.h:295
Definition of macros used internally by GUL.
Namespace gul14 contains all functions and classes of the General Utility Library.
Definition: doxygen.h:26
Helper type trait object to determine if a type is a container.
Definition: traits.h:47