Templa 0.0.1-alpha
C++ Metaprogramming Utilities
Loading...
Searching...
No Matches
traits.hpp
Go to the documentation of this file.
1#pragma once
2#include <iostream>
3#include <functional>
12
16
21namespace templa::traits
22{
23
32 template <typename T>
33 struct strip
34 {
35 using type = T;
36 };
37
38 template <typename T>
39 struct strip<const T>
40 {
41 using type = strip<T>::type;
42 };
43
44 template <typename T>
45 struct strip<volatile T>
46 {
47 using type = strip<T>::type;
48 };
49
50 template <typename T>
51 struct strip<const volatile T>
52 {
53 using type = strip<T>::type;
54 };
55
56 template <typename T>
57 struct strip<T *>
58 {
59 using type = strip<T>::type;
60 };
61
62 template <typename T>
63 struct strip<const T *>
64 {
65 using type = strip<T>::type;
66 };
67
68 template <typename T>
69 struct strip<volatile T *>
70 {
71 using type = strip<T>::type;
72 };
73
74 template <typename T>
75 struct strip<const volatile T *>
76 {
77 using type = strip<T>::type;
78 };
79
89 template <typename T>
90 using strip_t = strip<T>::type;
91
97
101
108 template <class F>
110 {
111 private:
112 using call_type = function_traits<decltype(&F::type::operator())>;
113
114 public:
117
119 static constexpr std::size_t arity = call_type::arity - 1;
120
125 template <std::size_t N>
126 struct argument
127 {
128 static_assert(N < arity, "error: invalid parameter index.");
130 using type = typename call_type::template argument<N + 1>::type;
131 };
132 };
133
140 template <typename R, typename... Args>
141 struct function_traits<R(Args...)>
142 {
144 using return_type = R;
145
147 static constexpr std::size_t arity = sizeof...(Args);
148
153 template <std::size_t N>
154 struct argument
155 {
156 static_assert(N < arity, "error: invalid parameter index.");
158 using type = typename std::tuple_element<N, std::tuple<Args...>>::type;
159 };
160 };
161
165 template <class R, class... Args>
166 struct function_traits<R (*)(Args...)> : public function_traits<R(Args...)>
167 {
168 };
169
173 template <class C, class R, class... Args>
174 struct function_traits<R (C::*)(Args...)> : public function_traits<R(C &, Args...)>
175 {
176 };
177
181 template <class C, class R, class... Args>
182 struct function_traits<R (C::*)(Args...) const> : public function_traits<R(C &, Args...)>
183 {
184 };
185
189 template <class C, class R>
190 struct function_traits<R(C::*)> : public function_traits<R(C &)>
191 {
192 };
193
197 template <class F>
199 {
200 };
201
205 template <class F>
207 {
208 };
209
211
212}
Retrieves the type of the N-th argument.
Definition traits.hpp:127
typename call_type::template argument< N+1 >::type type
The type of the N-th argument.
Definition traits.hpp:130
Retrieves the type of the N-th argument.
Definition traits.hpp:155
typename std::tuple_element< N, std::tuple< Args... > >::type type
Type of the N-th argument.
Definition traits.hpp:158
R return_type
Return type of the function.
Definition traits.hpp:144
static constexpr std::size_t arity
Number of function parameters.
Definition traits.hpp:147
Primary template for function traits. Specialization used to extract traits from functor types (e....
Definition traits.hpp:110
typename call_type::return_type return_type
Definition traits.hpp:116
static constexpr std::size_t arity
Definition traits.hpp:119
Recursively strips const, volatile qualifiers and pointers from a type.
Definition traits.hpp:34
strip< T >::type strip_t
Helper alias for strip.
Definition traits.hpp:90