tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
invoke_result.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_TYPE_TRAITS_INVOKE_RESULT_HPP
4#define TETL_TYPE_TRAITS_INVOKE_RESULT_HPP
5
13
14namespace etl {
15
16namespace detail {
17
18template <typename T>
19struct invoke_impl {
20 template <typename F, typename... Args>
21 static auto call(F&& f, Args&&... args) -> decltype(etl::forward<F>(f)(etl::forward<Args>(args)...));
22};
23
24template <typename B, typename MT>
25struct invoke_impl<MT B::*> {
26 template <typename T, typename Td = decay_t<T>>
27 requires is_base_of_v<B, Td>
28 static auto get(T&& t) -> T&&;
29
30 template <typename T, typename Td = decay_t<T>>
32 static auto get(T&& t) -> decltype(t.get());
33
34 template <typename T, typename Td = decay_t<T>>
36 static auto get(T&& t) -> decltype(*etl::forward<T>(t));
37
38 template <typename T, typename... Args, typename MT1>
39 requires is_function_v<MT1>
40 static auto call(MT1 B::* pmf, T&& t, Args&&... args)
41 -> decltype((invoke_impl::get(etl::forward<T>(t)).*pmf)(etl::forward<Args>(args)...));
42
43 template <typename T>
44 static auto call(MT B::* pmd, T&& t) -> decltype(invoke_impl::get(etl::forward<T>(t)).*pmd);
45};
46
47template <typename F, typename... Args, typename Fd = decay_t<F>>
48auto INVOKE(F&& f, Args&&... args) -> decltype(invoke_impl<Fd>::call(etl::forward<F>(f), etl::forward<Args>(args)...));
49
50template <typename AlwaysVoid, typename, typename...>
51struct invoke_result { };
52
53template <typename F, typename... Args>
54struct invoke_result<decltype(void(detail::INVOKE(declval<F>(), declval<Args>()...))), F, Args...> {
55 using type = decltype(detail::INVOKE(declval<F>(), declval<Args>()...));
56};
57
58} // namespace detail
59
70template <typename F, typename... ArgTypes>
71struct invoke_result : detail::invoke_result<void, F, ArgTypes...> { };
72
75template <typename F, typename... ArgTypes>
76using invoke_result_t = typename invoke_result<F, ArgTypes...>::type;
77
78} // namespace etl
79
80#endif // TETL_TYPE_TRAITS_INVOKE_RESULT_HPP
typename invoke_result< F, ArgTypes... >::type invoke_result_t
Definition invoke_result.hpp:76
Definition adjacent_find.hpp:8
constexpr bool is_base_of_v
Definition is_base_of.hpp:39
auto declval() noexcept -> add_rvalue_reference_t< T >
typename etl::decay< T >::type decay_t
Definition decay.hpp:32
constexpr auto get(complex< X > &z) noexcept -> X &
Definition complex.hpp:92
constexpr bool is_function_v
Checks whether T is a function type. Types like etl::inplace_function, lambdas, classes with overload...
Definition is_function.hpp:35
constexpr auto forward(remove_reference_t< T > &param) noexcept -> T &&
Forwards lvalues as either lvalues or as rvalues, depending on T. When t is a forwarding reference (a...
Definition forward.hpp:18
static constexpr bool value
Definition integral_constant.hpp:10
Deduces the return type of an INVOKE expression at compile time.
Definition invoke_result.hpp:71