Embedded Template Library
1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
initializer_list.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
Documentation: https://www.etlcpp.com/initializer_list.html
11
12
Copyright(c) 2022 John Wellbelove
13
14
Permission is hereby granted, free of charge, to any person obtaining a copy
15
of this software and associated documentation files(the "Software"), to deal
16
in the Software without restriction, including without limitation the rights
17
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
18
copies of the Software, and to permit persons to whom the Software is
19
furnished to do so, subject to the following conditions :
20
21
The above copyright notice and this permission notice shall be included in all
22
copies or substantial portions of the Software.
23
24
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
27
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
SOFTWARE.
31
******************************************************************************/
32
33
#ifndef ETL_INITIALIZER_LIST_INCLUDED
34
#define ETL_INITIALIZER_LIST_INCLUDED
35
36
#include "
platform.h
"
37
38
#if ETL_HAS_INITIALIZER_LIST
39
40
#if (ETL_USING_CPP11 && !defined(ETL_NO_INITIALIZER_LIST))
41
42
#include <stddef.h>
43
44
// Use the compiler's std::initializer_list?
45
#if (ETL_USING_STL && ETL_NOT_USING_STLPORT && !defined(ETL_FORCE_ETL_INITIALIZER_LIST)) || defined(ETL_IN_UNIT_TEST) \
46
|| defined(ETL_FORCE_STD_INITIALIZER_LIST)
47
48
#include <initializer_list>
49
50
#else
51
52
// Use the ETL's std::initializer_list
53
namespace
std
54
{
55
#if defined(ETL_COMPILER_MICROSOFT)
56
61
template
<
typename
T>
62
class
initializer_list
63
{
64
public
:
65
66
using
value_type = T;
67
using
reference =
const
T&;
68
using
const_reference =
const
T&;
69
using
size_type = size_t;
70
using
iterator =
const
T*;
71
using
const_iterator =
const
T*;
72
73
//*************************************************************************
75
//*************************************************************************
76
constexpr
initializer_list() ETL_NOEXCEPT
77
: pfirst(
nullptr
)
78
, plast(
nullptr
)
79
{
80
}
81
82
//*************************************************************************
84
//*************************************************************************
85
constexpr
initializer_list(
const
T* pfirst_,
const
T* plast_) ETL_NOEXCEPT
86
: pfirst(pfirst_)
87
, plast(plast_)
88
{
89
}
90
91
//*************************************************************************
93
//*************************************************************************
94
constexpr
const
T*
begin
() const ETL_NOEXCEPT
95
{
96
return
pfirst;
97
}
98
99
//*************************************************************************
101
//*************************************************************************
102
constexpr
const
T*
end
() const ETL_NOEXCEPT
103
{
104
return
plast;
105
}
106
107
//*************************************************************************
109
//*************************************************************************
110
constexpr
size_t
size
() const ETL_NOEXCEPT
111
{
112
return
static_cast<
size_t
>
(plast - pfirst);
113
}
114
115
private
:
116
117
const
T* pfirst;
118
const
T* plast;
119
};
120
121
//*************************************************************************
123
//*************************************************************************
124
template
<
typename
T>
125
constexpr
const
T*
begin
(initializer_list<T> init) ETL_NOEXCEPT
126
{
127
return
init.begin();
128
}
129
130
//*************************************************************************
132
//*************************************************************************
133
template
<
typename
T>
134
constexpr
const
T*
end
(initializer_list<T> init) ETL_NOEXCEPT
135
{
136
return
init.end();
137
}
138
139
#elif defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_CLANG) || defined(ETL_COMPILER_ARM6) || defined(ETL_COMPILER_ARM7) \
140
|| defined(ETL_COMPILER_IAR) || defined(ETL_COMPILER_TEXAS_INSTRUMENTS) || defined(ETL_COMPILER_INTEL)
141
146
template
<
class
T>
147
class
initializer_list
148
{
149
public
:
150
151
using
value_type = T;
152
using
reference =
const
T&;
153
using
const_reference =
const
T&;
154
using
size_type = size_t;
155
using
iterator =
const
T*;
156
using
const_iterator =
const
T*;
157
158
//*************************************************************************
160
//*************************************************************************
161
constexpr
initializer_list() ETL_NOEXCEPT
162
: pfirst(
nullptr
)
163
, length(0)
164
{
165
}
166
167
//*************************************************************************
169
//*************************************************************************
170
constexpr
const
T*
begin
() const ETL_NOEXCEPT
171
{
172
return
pfirst;
173
}
174
175
//*************************************************************************
177
//*************************************************************************
178
constexpr
const
T*
end
() const ETL_NOEXCEPT
179
{
180
return
pfirst + length;
181
}
182
183
//*************************************************************************
185
//*************************************************************************
186
constexpr
size_t
size
() const ETL_NOEXCEPT
187
{
188
return
length;
189
}
190
191
private
:
192
193
//*************************************************************************
195
//*************************************************************************
196
constexpr
initializer_list(
const
T* pfirst_,
size_t
length_) ETL_NOEXCEPT
197
: pfirst(pfirst_)
198
, length(length_)
199
{
200
}
201
202
const
T* pfirst;
203
size_t
length;
204
};
205
206
//*************************************************************************
208
//*************************************************************************
209
template
<
class
T>
210
constexpr
const
T*
begin
(initializer_list<T> init) ETL_NOEXCEPT
211
{
212
return
init.begin();
213
}
214
215
//*************************************************************************
217
//*************************************************************************
218
template
<
class
T>
219
constexpr
const
T*
end
(initializer_list<T> init) ETL_NOEXCEPT
220
{
221
return
init.end();
222
}
223
#else
224
225
#error No definition for initializer_list is currently available for your compiler. Visit https:
//github.com/ETLCPP/etl/issues to request support.
226
227
#endif
// Compiler tests
228
}
// namespace std
229
230
#endif
// (ETL_USING_STL && ETL_NOT_USING_STLPORT &&
231
// !defined(ETL_FORCE_ETL_INITIALIZER_LIST)) ||
232
// defined(ETL_IN_UNIT_TEST) ||
233
// defined(ETL_FORCE_STD_INITIALIZER_LIST)
234
#endif
// ETL_USING_CPP11 && !defined(ETL_NO_INITIALIZER_LIST)
235
#endif
// ETL_HAS_INITIALIZER_LIST
236
#endif
// ETL_INITIALIZER_LIST_INCLUDED
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
etl::begin
TContainer::iterator begin(TContainer &container)
Definition
iterator.h:1136
platform.h
include
etl
initializer_list.h
Generated on
for Embedded Template Library by
1.17.0