|
| 1 | +// |
| 2 | +// Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com) |
| 3 | +// |
| 4 | +// Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | +// |
| 7 | +// Official repository: https://github.com/cppalliance/rts |
| 8 | +// |
| 9 | + |
| 10 | +#ifndef BOOST_RTS_DETAIL_CALL_TRAITS_HPP |
| 11 | +#define BOOST_RTS_DETAIL_CALL_TRAITS_HPP |
| 12 | + |
| 13 | +#include <boost/rts/detail/type_traits.hpp> |
| 14 | +#include <type_traits> |
| 15 | + |
| 16 | +namespace boost { |
| 17 | +namespace rts { |
| 18 | +namespace detail { |
| 19 | + |
| 20 | +template<class... Ts> struct type_list {}; |
| 21 | + |
| 22 | +template<class T, class = void> |
| 23 | +struct call_traits : std::false_type |
| 24 | +{ |
| 25 | +}; |
| 26 | + |
| 27 | +template<class R, class... Args> |
| 28 | +struct call_traits<R(*)(Args...)> : std::true_type |
| 29 | +{ |
| 30 | + using return_type = R; |
| 31 | + using arg_types = type_list<Args...>; |
| 32 | +}; |
| 33 | + |
| 34 | +template<class R, class... Args> |
| 35 | +struct call_traits<R(&)(Args...)> : std::true_type |
| 36 | +{ |
| 37 | + using return_type = R; |
| 38 | + using arg_types = type_list<Args...>; |
| 39 | +}; |
| 40 | + |
| 41 | +template<class C, class R, class... Args> |
| 42 | +struct call_traits<R(C::*)(Args...)> : std::true_type |
| 43 | +{ |
| 44 | + using class_type = C; |
| 45 | + using return_type = R ; |
| 46 | + using arg_types = type_list<Args...>; |
| 47 | +}; |
| 48 | + |
| 49 | +template<class C, class R, class... Args> |
| 50 | +struct call_traits<R(C::*)(Args...) const> : std::true_type |
| 51 | +{ |
| 52 | + using class_type = C; |
| 53 | + using return_type = R ; |
| 54 | + using arg_types = type_list<Args...>; |
| 55 | +}; |
| 56 | + |
| 57 | +template<class F> |
| 58 | +struct call_traits<F, typename std::enable_if< |
| 59 | + std::is_member_function_pointer<decltype( |
| 60 | + &F::operator())>::value>::type> |
| 61 | + : call_traits<decltype(&F::operator())> |
| 62 | +{ |
| 63 | +}; |
| 64 | + |
| 65 | +template<class T, class R, class ArgList, class = void> |
| 66 | +struct is_invocable_impl : std::false_type {}; |
| 67 | + |
| 68 | +template<class T, class R, class... Args> |
| 69 | +struct is_invocable_impl< |
| 70 | + T, R, type_list<Args...>, |
| 71 | + void_t<decltype(std::declval<T>()( |
| 72 | + std::declval<Args>()...))>> |
| 73 | + : std::integral_constant<bool, |
| 74 | + call_traits<T>::value && |
| 75 | + std::is_convertible<decltype(std::declval<T>()( |
| 76 | + std::declval<Args>()...)), R>::value> |
| 77 | +{ |
| 78 | +}; |
| 79 | + |
| 80 | +template<class T, class R, class... Args> |
| 81 | +struct is_invocable |
| 82 | + : is_invocable_impl<T, R, type_list<Args...>> |
| 83 | +{ |
| 84 | +}; |
| 85 | + |
| 86 | +} // detail |
| 87 | +} // rts |
| 88 | +} // boost |
| 89 | + |
| 90 | +#endif |
0 commit comments