31#ifndef ETL_INVOKE_INCLUDED
32#define ETL_INVOKE_INCLUDED
50 template <
typename TFunction,
typename TRefWrapper,
typename... TArgs,
51 typename = etl::enable_if_t< etl::is_member_function_pointer<etl::decay_t<TFunction>>::value
52 && etl::is_reference_wrapper<etl::decay_t<TRefWrapper>>::value>>
53 ETL_CONSTEXPR
auto invoke(TFunction&& f, TRefWrapper&& ref_wrapper, TArgs&&... args) ->
decltype((ref_wrapper.get().*f)(etl::forward<TArgs>(args)...))
55 return (ref_wrapper.get().*f)(etl::forward<TArgs>(args)...);
61 typename TFunction,
typename TPtr,
typename... TArgs,
62 typename = etl::enable_if_t< etl::is_member_function_pointer<etl::decay_t<TFunction>>::value && etl::is_pointer<etl::decay_t<TPtr>>::value>>
63 ETL_CONSTEXPR
auto invoke(TFunction&& f, TPtr&& ptr, TArgs&&... args) ->
decltype(((*etl::forward<TPtr>(ptr)).*f)(etl::forward<TArgs>(args)...))
65 return ((*etl::forward<TPtr>(ptr)).*f)(etl::forward<TArgs>(args)...);
70 template <
typename TFunction,
typename TObject,
typename... TArgs,
71 typename = etl::enable_if_t< etl::is_member_function_pointer<etl::decay_t<TFunction>>::value
73 ETL_CONSTEXPR
auto invoke(TFunction&& f, TObject&& obj, TArgs&&... args) ->
decltype((etl::forward<TObject>(obj).*f)(etl::forward<TArgs>(args)...))
75 return (etl::forward<TObject>(obj).*f)(etl::forward<TArgs>(args)...);
80 template <
typename TFunction,
typename TRefWrapper,
81 typename = etl::enable_if_t< etl::is_member_object_pointer<etl::decay_t<TFunction>>::value
82 && etl::is_reference_wrapper<etl::decay_t<TRefWrapper>>::value>>
83 ETL_CONSTEXPR
auto invoke(TFunction&& f, TRefWrapper&& ref_wrapper) ->
decltype(ref_wrapper.get().*f)
85 return ref_wrapper.get().*f;
91 typename TFunction,
typename TPtr,
92 typename = etl::enable_if_t< etl::is_member_object_pointer<etl::decay_t<TFunction>>::value && etl::is_pointer<etl::decay_t<TPtr>>::value>>
93 ETL_CONSTEXPR
auto invoke(TFunction&& f, TPtr&& ptr) ->
decltype(((*etl::forward<TPtr>(ptr)).*f))
95 return ((*etl::forward<TPtr>(ptr)).*f);
100 template <
typename TFunction,
typename TObject,
101 typename = etl::enable_if_t< etl::is_member_object_pointer<etl::decay_t<TFunction>>::value
103 ETL_CONSTEXPR
auto invoke(TFunction&& f, TObject&& obj) ->
decltype(etl::forward<TObject>(obj).*f)
105 return etl::forward<TObject>(obj).*f;
110 template <
typename TFunction,
typename... TArgs,
111 typename = etl::enable_if_t< etl::is_reference_wrapper<etl::decay_t<TFunction>>::value
112 && !etl::is_member_pointer<etl::decay_t< decltype(etl::declval<TFunction>().get())>>::value>>
113 ETL_CONSTEXPR
auto invoke(TFunction&& f, TArgs&&... args) ->
decltype(f.get()(etl::forward<TArgs>(args)...))
115 return f.get()(etl::forward<TArgs>(args)...);
121 template <
typename TFunction,
typename... TArgs,
122 typename = etl::enable_if_t< etl::is_reference_wrapper<etl::decay_t<TFunction>>::value
123 && etl::is_member_pointer<etl::decay_t< decltype(etl::declval<TFunction>().get())>>::value>,
125 ETL_CONSTEXPR
auto invoke(TFunction&& f, TArgs&&... args) ->
decltype(etl::invoke(f.get(), etl::forward<TArgs>(args)...))
127 return etl::invoke(f.get(), etl::forward<TArgs>(args)...);
132 template <
typename TFunction,
typename... TArgs,
133 typename = etl::enable_if_t< !etl::is_member_pointer<etl::decay_t<TFunction>>::value
134 && !etl::is_reference_wrapper<etl::decay_t<TFunction>>::value>>
135 ETL_CONSTEXPR
auto invoke(TFunction&& f, TArgs&&... args) ->
decltype(etl::forward<TFunction>(f)(etl::forward<TArgs>(args)...))
137 return etl::forward<TFunction>(f)(etl::forward<TArgs>(args)...);
143 namespace private_invoke
148 template <
typename TFunction,
typename... TArgs>
149 struct is_invocable_expr
151 template <
typename U>
152 static auto test(
int) ->
decltype((void)etl::invoke(etl::declval<U>(), etl::declval<TArgs>()...), etl::true_type{});
157 using type =
decltype(test<TFunction>(0));
159 static ETL_CONSTANT
bool value = type::value;
166 template <
typename TFunction,
typename... TArgs>
167 struct is_invocable_expr<TFunction, etl::type_list<TArgs...>>
169 template <
typename U>
170 static auto test(
int) ->
decltype((void)etl::invoke(etl::declval<U>(), etl::declval<TArgs>()...), etl::true_type{});
175 using type =
decltype(test<TFunction>(0));
177 static ETL_CONSTANT
bool value = type::value;
182 template <
typename TFunction,
typename... TArgs>
183 struct invoke_result_impl
185 template <
typename U>
186 static auto test(
int) ->
decltype(etl::invoke(etl::declval<U>(), etl::declval<TArgs>()...));
189 static void test(...);
191 using type =
decltype(test<TFunction>(0));
196 template <
typename TFunction,
typename... TArgs>
197 struct invoke_result_impl<TFunction, etl::type_list<TArgs...>>
199 template <
typename U>
200 static auto test(
int) ->
decltype(etl::invoke(etl::declval<U>(), etl::declval<TArgs>()...));
203 static void test(...);
205 using type =
decltype(test<TFunction>(0));
208 template <
typename TFunction,
typename... TArgs>
209 using invoke_result_impl_t =
typename invoke_result_impl<TFunction, TArgs...>::type;
214 template <
typename TFunction,
bool = etl::is_reference_wrapper<etl::decay_t<TFunction>>::value>
215 struct unwrap_ref_callable
217 using type = TFunction;
220 template <
typename TFunction>
221 struct unwrap_ref_callable<TFunction, true>
223 using type = etl::unwrap_ref_decay_t<TFunction>;
226 template <
typename TFunction>
227 using unwrap_ref_callable_t =
typename unwrap_ref_callable<TFunction>::type;
232 template <
typename TFunction>
233 using effective_callable_t = etl::conditional_t< etl::is_function<etl::remove_reference_t<TFunction>>::value,
234 etl::add_pointer_t<etl::remove_reference_t<TFunction>>, unwrap_ref_callable_t<TFunction>>;
239 template <
typename TFunction,
typename,
typename... TArgs>
246 template <
typename TFunction,
typename... TArgs>
247 struct invoke_result< TFunction, etl::void_t<decltype(etl::invoke(etl::declval<TFunction>(), etl::declval<TArgs>()...))>, TArgs...>
251 using FC = private_invoke::effective_callable_t<TFunction>;
255 using type = etl::conditional_t<private_invoke::is_invocable_expr<FC, TArgs...>::value, private_invoke::invoke_result_impl_t<FC, TArgs...>,
void>;
260 template <
typename TFunction,
typename... TArgs>
261 struct invoke_result<TFunction, etl::type_list<TArgs...>>
265 using FC = private_invoke::effective_callable_t<TFunction>;
269 using type = etl::conditional_t<private_invoke::is_invocable_expr<FC, TArgs...>::value, private_invoke::invoke_result_impl_t<FC, TArgs...>,
void>;
275 template <
typename TFunction,
typename... TArgs>
276 struct invoke_result< TFunction, etl::void_t<decltype(etl::invoke(etl::declval<TFunction>(), etl::declval<TArgs>()...))>, etl::type_list<TArgs...>>
278 using type =
decltype(etl::invoke(etl::declval<TFunction>(), etl::declval<TArgs>()...));
282 template <
typename TFunction,
typename... TArgs>
283 using invoke_result_t =
typename invoke_result<TFunction, void, TArgs...>::type;
287 template <
typename TFunction,
typename... TArgs>
288 struct is_invocable : etl::bool_constant< private_invoke::is_invocable_expr< private_invoke::effective_callable_t<TFunction>, TArgs...>::value>
295 template <
typename TFunction,
typename... TArgs>
296 struct is_invocable<TFunction, etl::type_list<TArgs...>> : is_invocable<TFunction, TArgs...>
302 template <
typename TReturn,
typename TFunction,
typename... TArgs>
303 struct is_invocable_r
304 : etl::conditional_t<
305 etl::is_same<TReturn, void>::value, etl::is_invocable<TFunction, TArgs...>,
306 etl::conditional_t< is_invocable<TFunction, TArgs...>::value,
307 etl::bool_constant<etl::is_convertible< invoke_result_t<TFunction, TArgs...>, TReturn>::value>, etl::false_type>>
314 template <
typename TReturn,
typename TFunction,
typename... TArgs>
315 struct is_invocable_r<TReturn, TFunction, etl::type_list<TArgs...>> : is_invocable_r<TReturn, TFunction, TArgs...>
322 template <
typename TFunction,
typename TObject,
typename... TArgs>
323 struct is_invocable<TFunction, TObject, etl::type_list<TArgs...>> : is_invocable<TFunction, TObject, TArgs...>
329 template <
typename TReturn,
typename TFunction,
typename TObject,
typename... TArgs>
330 struct is_invocable_r<TReturn, TFunction, TObject, etl::type_list<TArgs...>> : is_invocable_r<TReturn, TFunction, TObject, TArgs...>
337 template <
typename TFunction,
typename... TArgs>
338 struct is_nothrow_invocable
339 : etl::bool_constant< etl::is_invocable<TFunction, TArgs...>::value
340 && etl::function_traits< private_invoke::effective_callable_t<TFunction>>::is_noexcept>
346 template <
typename TReturn,
typename TFunction,
typename... TArgs>
347 struct is_nothrow_invocable_r
348 : etl::bool_constant< etl::is_invocable_r<TReturn, TFunction, TArgs...>::value
349 && etl::function_traits< private_invoke::effective_callable_t<TFunction>>::is_noexcept
350 && (etl::is_same<TReturn, void>::value
351 || etl::is_nothrow_convertible<invoke_result_t<TFunction, TArgs...>, TReturn>::value)>
357 template <
typename TReturn,
typename TFunction,
typename... TArgs>
358 struct is_nothrow_invocable_r<TReturn, TFunction, etl::type_list<TArgs...>>
359 : etl::bool_constant< etl::is_invocable_r<TReturn, TFunction, TArgs...>::value
360 && etl::function_traits< private_invoke::effective_callable_t<TFunction>>::is_noexcept
361 && (etl::is_same<TReturn, void>::value
362 || etl::is_nothrow_convertible<invoke_result_t<TFunction, TArgs...>, TReturn>::value)>
369 template <
typename TReturn,
typename TFunction,
typename TObject,
typename... TArgs>
370 struct is_nothrow_invocable_r<TReturn, TFunction, TObject, etl::type_list<TArgs...>> : is_nothrow_invocable_r<TReturn, TFunction, TObject, TArgs...>
376 template <
typename TFunction,
typename... TArgs>
377 inline constexpr bool is_invocable_v = is_invocable<TFunction, TArgs...>::value;
379 template <
typename TReturn,
typename TFunction,
typename... TArgs>
380 inline constexpr bool is_invocable_r_v = is_invocable_r<TReturn, TFunction, TArgs...>::value;
382 template <
typename TFunction,
typename... TArgs>
383 inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<TFunction, TArgs...>::value;
385 template <
typename TFunction,
typename... TArgs>
386 inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<TFunction, TArgs...>::value;
bitset_ext
Definition absolute.h:40
integral_constant< bool, false > false_type
integral_constant specialisations
Definition type_traits.h:80
Definition functional.h:164