Embedded Template Library 1.0
class_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) 2021 jwellbelove
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_CLASS_TRAITS_INCLUDED
32#define ETL_CLASS_TRAITS_INCLUDED
33
34#include <stddef.h>
35#include <stdint.h>
36#include <utility>
37
38#include "platform.h"
39
40#if ETL_CPP11_SUPPORTED
41
42namespace etl
43{
44#if ETL_CPP11_SUPPORTED
45 //***************************************************************************
47 //***************************************************************************
48 template <typename T>
49 class has_begin
50 {
51 typedef char one;
52 struct two { char x[2]; };
53
54 template <typename C> static constexpr one test(decltype(&C::begin)*);
55 template <typename C> static constexpr two test(...);
56
57 public:
58
59 static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
60 };
61
62#if ETL_CPP17_SUPPORTED
63 template <typename T>
64 static constexpr bool has_begin_v = has_begin<T>::value;
65#endif
66
67 //***************************************************************************
69 //***************************************************************************
70 template <typename T>
71 class has_end
72 {
73 typedef char one;
74 struct two { char x[2]; };
75
76 template <typename C> static constexpr one test(decltype(std::declval<C>().end()));
77 template <typename C> static constexpr two test(...);
78
79 public:
80
81 static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
82 };
83
84#if ETL_CPP17_SUPPORTED
85 template <typename T>
86 static constexpr bool has_end_v = hasend<T>::value;
87#endif
88
89 //***************************************************************************
91 //***************************************************************************
92 template <typename T>
93 class has_size
94 {
95 typedef char one;
96 struct two { char x[2]; };
97
98 template <typename C> static one test(decltype(std::declval<C>().size()));
99 template <typename C> static two test(...);
100
101 public:
102
103 static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
104 };
105
106#if ETL_CPP17_SUPPORTED
107 template <typename T>
108 static constexpr bool has_size_v = has_size<T>::value;
109#endif
110
111 //***************************************************************************
113//***************************************************************************
114 template <typename T>
115 class has_max_size
116 {
117 typedef char one;
118 struct two { char x[2]; };
119
120 template <typename C> static one test(decltype(std::declval<C>().max_size()));
121 template <typename C> static two test(...);
122
123 public:
124
125 static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
126 };
127
128#if ETL_CPP17_SUPPORTED
129 template <typename T>
130 static constexpr bool has_max_size_v = has_max_size<T>::value;
131#endif
132
133 //***************************************************************************
135 //***************************************************************************
136 template <typename T>
137 class has_empty
138 {
139 typedef char one;
140 struct two { char x[2]; };
141
142 template <typename C> static constexpr one test(decltype(std::declval<C>().empty()));
143 template <typename C> static constexpr two test(...);
144
145 public:
146
147 static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
148 };
149
150#if ETL_CPP17_SUPPORTED
151 template <typename T>
152 static constexpr bool has_empty_v = has_empty<T>::value;
153#endif
154
155 //***************************************************************************
157 //***************************************************************************
158 template <typename T>
159 class has_data
160 {
161 typedef char one;
162 struct two { char x[2]; };
163
164 template <typename C> static constexpr one test(decltype(std::declval<C>().data()));
165 template <typename C> static constexpr two test(...);
166
167 public:
168
169 static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
170 };
171
172#if ETL_CPP17_SUPPORTED
173 template <typename T>
174 static constexpr bool has_data_v = has_data<T>::value;
175#endif
176#endif
177}
178
179#endif
180
181#endif // ETL_CLASS_TRAITS_INCLUDED
bitset_ext
Definition: absolute.h:38
size_t max_size() const
Returns the maximum number of items in the variant_pool.
Definition: variant_pool_generator.h:281
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition: iterator.h:931
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition: iterator.h:961