tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
is_invocable.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_TYPE_TRAITS_IS_INVOCABLE_HPP
4#define TETL_TYPE_TRAITS_IS_INVOCABLE_HPP
5
10
11namespace etl {
12
13namespace detail {
14
15template <typename Result, typename Ret, bool = etl::is_void_v<Ret>, typename = void>
16struct is_invocable_impl : etl::false_type { };
17
18template <typename Result, typename Ret>
19struct is_invocable_impl<Result, Ret, true, etl::void_t<typename Result::type>> : etl::true_type { };
20
21// Check if the return type can be converted to T
22template <typename Result, typename Ret>
23struct is_invocable_impl<Result, Ret, false, etl::void_t<typename Result::type>> {
24 static auto get_t() -> typename Result::type;
25 template <typename T>
26 static auto use_t(T /*ignore*/) -> void;
27 template <typename T, typename = decltype(use_t<T>(get_t()))>
28 static auto check_converts_to_t(int /*ignore*/) -> etl::true_type;
29 template <typename T>
30 static auto check_converts_to_t(...) -> etl::false_type;
31 using type = decltype(check_converts_to_t<Ret>(1));
32};
33
34} // namespace detail
35
36template <typename Fn, typename... ArgTypes>
37struct is_invocable : detail::is_invocable_impl<invoke_result<Fn, ArgTypes...>, void>::type { };
38
39template <typename Fn, typename... ArgTypes>
40inline constexpr auto is_invocable_v = is_invocable<Fn, ArgTypes...>::value;
41
42} // namespace etl
43
44#endif // TETL_TYPE_TRAITS_IS_INVOCABLE_HPP
void void_t
Definition void_t.hpp:10
Definition adjacent_find.hpp:8
constexpr auto is_invocable_v
Definition is_invocable.hpp:40
bool_constant< true > true_type
Definition bool_constant.hpp:13
bool_constant< false > false_type
Definition bool_constant.hpp:14
integral_constant< bool, Val > type
Definition integral_constant.hpp:12
Definition is_invocable.hpp:37