Embedded Template Library 1.0
Loading...
Searching...
No Matches
function_traits.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2025 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_FUNCTION_TRAITS_INCLUDED
32#define ETL_FUNCTION_TRAITS_INCLUDED
33
34#include "platform.h"
35#include "type_list.h"
36#include "type_traits.h"
37
38#if ETL_USING_CPP11
39namespace etl
40{
41 //***************************************************************************
43 //***************************************************************************
44 template <typename T>
45 struct function_traits;
46
47 //***************************************************************************
49 //***************************************************************************
50 template <typename TReturn, typename... TArgs>
51 struct function_traits<TReturn(*)(TArgs...)>
52 {
53 using function_type = TReturn(TArgs...);
54 using return_type = TReturn;
55 using object_type = void;
56 using argument_types = etl::type_list<TArgs...>;
57
58 static constexpr bool is_function = true;
59 static constexpr bool is_member_function = false;
60 static constexpr bool is_const = false;
61 static constexpr size_t argument_count = sizeof...(TArgs);
62 };
63
64 template <typename TReturn, typename... TArgs>
65 constexpr bool function_traits<TReturn(*)(TArgs...)>::is_function;
66
67 template <typename TReturn, typename... TArgs>
68 constexpr bool function_traits<TReturn(*)(TArgs...)>::is_member_function;
69
70 template <typename TReturn, typename... TArgs>
71 constexpr bool function_traits<TReturn(*)(TArgs...)>::is_const;
72
73 template <typename TReturn, typename... TArgs>
74 constexpr size_t function_traits<TReturn(*)(TArgs...)>::argument_count;
75
76 //***************************************************************************
78 //***************************************************************************
79 template <typename TReturn, typename TObject, typename... TArgs>
80 struct function_traits<TReturn(TObject::*)(TArgs...)>
81 {
82 using function_type = TReturn(TArgs...);
83 using return_type = TReturn;
84 using object_type = TObject;
86
87 static constexpr bool is_function = false;
88 static constexpr bool is_member_function = true;
89 static constexpr bool is_const = false;
90 static constexpr size_t argument_count = sizeof...(TArgs);
91 };
92
93 template <typename TReturn, typename TObject, typename... TArgs>
94 constexpr bool function_traits<TReturn(TObject::*)(TArgs...)>::is_function;
95
96 template <typename TReturn, typename TObject, typename... TArgs>
97 constexpr bool function_traits<TReturn(TObject::*)(TArgs...)>::is_member_function;
98
99 template <typename TReturn, typename TObject, typename... TArgs>
100 constexpr bool function_traits<TReturn(TObject::*)(TArgs...)>::is_const;
101
102 template <typename TReturn, typename TObject, typename... TArgs>
103 constexpr size_t function_traits<TReturn(TObject::*)(TArgs...)>::argument_count;
104
105 //***************************************************************************
107 //***************************************************************************
108 template <typename TReturn, typename TObject, typename... TArgs>
109 struct function_traits<TReturn(TObject::*)(TArgs...) const>
110 {
111 using function_type = TReturn(TArgs...);
112 using return_type = TReturn;
113 using object_type = TObject;
115
116 static constexpr bool is_function = false;
117 static constexpr bool is_member_function = true;
118 static constexpr bool is_const = true;
119 static constexpr size_t argument_count = sizeof...(TArgs);
120 };
121
122 template <typename TReturn, typename TObject, typename... TArgs>
123 constexpr bool function_traits<TReturn(TObject::*)(TArgs...) const>::is_function;
124
125 template <typename TReturn, typename TObject, typename... TArgs>
126 constexpr bool function_traits<TReturn(TObject::*)(TArgs...) const>::is_member_function;
127
128 template <typename TReturn, typename TObject, typename... TArgs>
129 constexpr bool function_traits<TReturn(TObject::*)(TArgs...) const>::is_const;
130
131 template <typename TReturn, typename TObject, typename... TArgs>
132 constexpr size_t function_traits<TReturn(TObject::*)(TArgs...) const>::argument_count;
133}
134#endif
135
136#endif
bitset_ext
Definition absolute.h:38
pair holds two objects of arbitrary type
Definition utility.h:164
ETL_CONSTEXPR pair()
Default constructor.
Definition utility.h:176