ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
function_traits.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2023 - present.
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// https://www.boost.org/LICENSE_1_0.txt)
7//
8// Project home: https://github.com/victimsnino/ReactivePlusPlus
9//
10
11#pragma once
12
13#include <rpp/utils/tuple.hpp>
14
15#include <type_traits>
16
17namespace rpp::utils
18{
19 template<typename T, typename = void>
20 struct is_not_template_callable_t : std::false_type
21 {
22 };
23
24 template<typename T>
25 struct is_not_template_callable_t<T, std::void_t<decltype(&T::operator())>> : std::true_type
26 {
27 };
28
29 template<class T, class R, class... Args>
30 struct is_not_template_callable_t<R (T::*)(Args...) const> : std::true_type
31 {
32 };
33
34 template<class T, class R, class... Args>
35 struct is_not_template_callable_t<R (T::*)(Args...)> : std::true_type
36 {
37 };
38
39 template<class R, class... Args>
40 struct is_not_template_callable_t<R (*)(Args...)> : std::true_type
41 {
42 };
43
44 template<typename T>
45 concept is_not_template_callable = is_not_template_callable_t<T>::value;
46
47 // Lambda
48 template<is_not_template_callable T>
49 struct function_traits : function_traits<decltype(&T::operator())>
50 {
51 };
52
53 // Operator of lambda
54 template<class T, class R, class... Args>
55 struct function_traits<R (T::*)(Args...) const> : function_traits<R (*)(Args...)>
56 {
57 };
58
59 // Operator of lambda with mutable
60 template<class T, class R, class... Args>
61 struct function_traits<R (T::*)(Args...)> : function_traits<R (*)(Args...)>
62 {
63 };
64
65 // Classical global function no args
66 template<class R>
67 struct function_traits<R (*)()>
68 {
69 using result = R;
70 };
71
72 // Classical global function
73 template<class R, class... Args>
74 struct function_traits<R (*)(Args...)>
75 {
76 using result = R;
78
79 template<std::size_t I = 0>
80 requires (sizeof...(Args) > I)
81 using argument = typename arguments::template type_at_index_t<I>;
82 };
83
84 template<typename T, std::size_t I = 0>
85 using decayed_function_argument_t = typename function_traits<T>::template argument<I>;
86
87 template<typename Fn, typename... Args>
88 using decayed_invoke_result_t = std::decay_t<std::invoke_result_t<Fn, Args...>>;
89
90} // namespace rpp::utils
Definition tuple.hpp:105
Definition function_traits.hpp:45
Definition function_traits.hpp:50
Definition function_traits.hpp:21