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// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_TYPE_TRAITS_IS_INVOCABLE_HPP
5#define TETL_TYPE_TRAITS_IS_INVOCABLE_HPP
6
7#include <etl/_type_traits/bool_constant.hpp>
8#include <etl/_type_traits/invoke_result.hpp>
9#include <etl/_type_traits/is_void.hpp>
10#include <etl/_type_traits/void_t.hpp>
11
12namespace etl {
13
14namespace detail {
15
16template <typename Result, typename Ret, bool = etl::is_void_v<Ret>, typename = void>
17struct is_invocable_impl : etl::false_type { };
18
19template <typename Result, typename Ret>
20struct is_invocable_impl<Result, Ret, true, etl::void_t<typename Result::type>> : etl::true_type { };
21
22// Check if the return type can be converted to T
23template <typename Result, typename Ret>
24struct is_invocable_impl<Result, Ret, false, etl::void_t<typename Result::type>> {
25 static auto get_t() -> typename Result::type;
26 template <typename T>
27 static auto use_t(T /*ignore*/) -> void;
28 template <typename T, typename = decltype(use_t<T>(get_t()))>
29 static auto check_converts_to_t(int /*ignore*/) -> etl::true_type;
30 template <typename T>
31 static auto check_converts_to_t(...) -> etl::false_type;
32 using type = decltype(check_converts_to_t<Ret>(1));
33};
34
35} // namespace detail
36
37template <typename Fn, typename... ArgTypes>
38struct is_invocable : detail::is_invocable_impl<invoke_result<Fn, ArgTypes...>, void>::type { };
39
40template <typename Fn, typename... ArgTypes>
41inline constexpr auto is_invocable_v = is_invocable<Fn, ArgTypes...>::value;
42
43} // namespace etl
44
45#endif // TETL_TYPE_TRAITS_IS_INVOCABLE_HPP
Definition adjacent_find.hpp:9
constexpr auto is_invocable_v
Definition is_invocable.hpp:41
Deduces the return type of an INVOKE expression at compile time.
Definition invoke_result.hpp:72
Definition is_invocable.hpp:38