Embedded Template Library
1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
class_traits.h
Go to the documentation of this file.
1
2
3
/******************************************************************************
4
The MIT License(MIT)
5
6
Embedded Template Library.
7
https://github.com/ETLCPP/etl
8
https://www.etlcpp.com
9
10
Copyright(c) 2021 jwellbelove
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files(the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions :
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
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
42
namespace
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
53
{
54
char
x[2];
55
};
56
57
template
<
typename
C>
58
static
constexpr
one test(
decltype
(&C::begin)*);
59
template
<
typename
C>
60
static
constexpr
two test(...);
61
62
public
:
63
64
static
constexpr
bool
value = (
sizeof
(test<T>(0)) ==
sizeof
(char));
65
};
66
67
#if ETL_CPP17_SUPPORTED
68
template
<
typename
T>
69
static
constexpr
bool
has_begin_v = has_begin<T>::value;
70
#endif
71
72
//***************************************************************************
74
//***************************************************************************
75
template
<
typename
T>
76
class
has_end
77
{
78
typedef
char
one;
79
struct
two
80
{
81
char
x[2];
82
};
83
84
template
<
typename
C>
85
static
constexpr
one test(
decltype
(std::declval<C>().
end
()));
86
template
<
typename
C>
87
static
constexpr
two test(...);
88
89
public
:
90
91
static
constexpr
bool
value = (
sizeof
(test<T>(0)) ==
sizeof
(char));
92
};
93
94
#if ETL_CPP17_SUPPORTED
95
template
<
typename
T>
96
static
constexpr
bool
has_end_v = hasend<T>::value;
97
#endif
98
99
//***************************************************************************
101
//***************************************************************************
102
template
<
typename
T>
103
class
has_size
104
{
105
typedef
char
one;
106
struct
two
107
{
108
char
x[2];
109
};
110
111
template
<
typename
C>
112
static
one test(
decltype
(std::declval<C>().
size
()));
113
template
<
typename
C>
114
static
two test(...);
115
116
public
:
117
118
static
constexpr
bool
value = (
sizeof
(test<T>(0)) ==
sizeof
(char));
119
};
120
121
#if ETL_CPP17_SUPPORTED
122
template
<
typename
T>
123
static
constexpr
bool
has_size_v = has_size<T>::value;
124
#endif
125
126
//***************************************************************************
128
//***************************************************************************
129
template
<
typename
T>
130
class
has_max_size
131
{
132
typedef
char
one;
133
struct
two
134
{
135
char
x[2];
136
};
137
138
template
<
typename
C>
139
static
one test(
decltype
(std::declval<C>().max_size()));
140
template
<
typename
C>
141
static
two test(...);
142
143
public
:
144
145
static
constexpr
bool
value = (
sizeof
(test<T>(0)) ==
sizeof
(char));
146
};
147
148
#if ETL_CPP17_SUPPORTED
149
template
<
typename
T>
150
static
constexpr
bool
has_max_size_v = has_max_size<T>::value;
151
#endif
152
153
//***************************************************************************
155
//***************************************************************************
156
template
<
typename
T>
157
class
has_empty
158
{
159
typedef
char
one;
160
struct
two
161
{
162
char
x[2];
163
};
164
165
template
<
typename
C>
166
static
constexpr
one test(
decltype
(std::declval<C>().empty()));
167
template
<
typename
C>
168
static
constexpr
two test(...);
169
170
public
:
171
172
static
constexpr
bool
value = (
sizeof
(test<T>(0)) ==
sizeof
(char));
173
};
174
175
#if ETL_CPP17_SUPPORTED
176
template
<
typename
T>
177
static
constexpr
bool
has_empty_v = has_empty<T>::value;
178
#endif
179
180
//***************************************************************************
182
//***************************************************************************
183
template
<
typename
T>
184
class
has_data
185
{
186
typedef
char
one;
187
struct
two
188
{
189
char
x[2];
190
};
191
192
template
<
typename
C>
193
static
constexpr
one test(
decltype
(std::declval<C>().
data
()));
194
template
<
typename
C>
195
static
constexpr
two test(...);
196
197
public
:
198
199
static
constexpr
bool
value = (
sizeof
(test<T>(0)) ==
sizeof
(char));
200
};
201
202
#if ETL_CPP17_SUPPORTED
203
template
<
typename
T>
204
static
constexpr
bool
has_data_v = has_data<T>::value;
205
#endif
206
#endif
207
}
// namespace etl
208
209
#endif
210
211
#endif
// ETL_CLASS_TRAITS_INCLUDED
etl
Definition
absolute.h:40
etl::data
ETL_CONSTEXPR TContainer::pointer data(TContainer &container)
Definition
iterator.h:1470
etl::size
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition
iterator.h:1434
etl::end
TContainer::iterator end(TContainer &container)
Definition
iterator.h:1166
platform.h
include
etl
experimental
class_traits.h
Generated on
for Embedded Template Library by
1.17.0