Embedded Template Library  1.0
container.h
Go to the documentation of this file.
1 
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) 2014 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_CONTAINER_INCLUDED
32 #define ETL_CONTAINER_INCLUDED
33 
34 #include <stddef.h>
35 
36 #include "platform.h"
37 #include "iterator.h"
38 
41 
42 namespace etl
43 {
44  //*****************************************************************************
47  //*****************************************************************************
48  template<typename TContainer>
49  ETL_CONSTEXPR typename TContainer::iterator begin(TContainer& container)
50  {
51  return container.begin();
52  }
53 
54  //*****************************************************************************
57  //*****************************************************************************
58  template<typename TContainer>
59  ETL_CONSTEXPR typename TContainer::const_iterator begin(const TContainer& container)
60  {
61  return container.begin();
62  }
63 
64  //*****************************************************************************
67  //*****************************************************************************
68  template<typename TContainer>
69  ETL_CONSTEXPR typename TContainer::const_iterator cbegin(const TContainer& container)
70  {
71  return container.cbegin();
72  }
73 
74  //*****************************************************************************
77  //*****************************************************************************
78  template<typename TContainer>
79  ETL_CONSTEXPR typename TContainer::reverse_iterator rbegin(const TContainer& container)
80  {
81  return container.rbegin();
82  }
83 
84  //*****************************************************************************
87  //*****************************************************************************
88  template<typename TContainer>
89  ETL_CONSTEXPR typename TContainer::reverse_iterator crbegin(const TContainer& container)
90  {
91  return container.crbegin();
92  }
93 
94  //*****************************************************************************
97  //*****************************************************************************
98  template<typename TContainer>
99  ETL_CONSTEXPR typename TContainer::iterator end(TContainer& container)
100  {
101  return container.end();
102  }
103 
104  //*****************************************************************************
107  //*****************************************************************************
108  template<typename TContainer>
109  ETL_CONSTEXPR typename TContainer::const_iterator end(const TContainer& container)
110  {
111  return container.end();
112  }
113 
114  //*****************************************************************************
117  //*****************************************************************************
118  template<typename TContainer>
119  ETL_CONSTEXPR typename TContainer::const_iterator cend(const TContainer& container)
120  {
121  return container.cend();
122  }
123 
124  //*****************************************************************************
127  //*****************************************************************************
128  template<typename TContainer>
129  ETL_CONSTEXPR typename TContainer::const_iterator rend(const TContainer& container)
130  {
131  return container.rend();
132  }
133 
134  //*****************************************************************************
137  //*****************************************************************************
138  template<typename TContainer>
139  ETL_CONSTEXPR typename TContainer::reverse_iterator crend(const TContainer& container)
140  {
141  return container.crend();
142  }
143 
144  //*****************************************************************************
147  //*****************************************************************************
148  template<typename TValue, const size_t ARRAY_SIZE>
149  ETL_CONSTEXPR TValue* begin(TValue(&data)[ARRAY_SIZE])
150  {
151  return &data[0];
152  }
153 
154  //*****************************************************************************
157  //*****************************************************************************
158  template<typename TValue, const size_t ARRAY_SIZE>
159  ETL_CONSTEXPR const TValue* begin(const TValue(&data)[ARRAY_SIZE])
160  {
161  return &data[0];
162  }
163 
164  //*****************************************************************************
167  //*****************************************************************************
168  template<typename TValue, const size_t ARRAY_SIZE>
169  ETL_CONSTEXPR const TValue* cbegin(const TValue(&data)[ARRAY_SIZE])
170  {
171  return &data[0];
172  }
173 
174  //*****************************************************************************
177  //*****************************************************************************
178  template<typename TValue, const size_t ARRAY_SIZE>
179  ETL_OR_STD::reverse_iterator<TValue*> rbegin(const TValue(&data)[ARRAY_SIZE])
180  {
181  return ETL_OR_STD::reverse_iterator<TValue*>(&data[ARRAY_SIZE]);
182  }
183 
184  //*****************************************************************************
187  //*****************************************************************************
188  template<typename TValue, const size_t ARRAY_SIZE>
189  ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<const TValue*> crbegin(const TValue(&data)[ARRAY_SIZE])
190  {
191  return ETL_OR_STD::reverse_iterator<const TValue*>(&data[ARRAY_SIZE]);
192  }
193 
194  //*****************************************************************************
197  //*****************************************************************************
198  template<typename TValue, const size_t ARRAY_SIZE>
199  ETL_CONSTEXPR TValue* end(TValue(&data)[ARRAY_SIZE])
200  {
201  return &data[ARRAY_SIZE];
202  }
203 
204  //*****************************************************************************
207  //*****************************************************************************
208  template<typename TValue, const size_t ARRAY_SIZE>
209  ETL_CONSTEXPR const TValue* end(const TValue(&data)[ARRAY_SIZE])
210  {
211  return &data[ARRAY_SIZE];
212  }
213 
214  //*****************************************************************************
217  //*****************************************************************************
218  template<typename TValue, const size_t ARRAY_SIZE>
219  ETL_CONSTEXPR const TValue* cend(const TValue(&data)[ARRAY_SIZE])
220  {
221  return &data[ARRAY_SIZE];
222  }
223 
224  //*****************************************************************************
227  //*****************************************************************************
228  template<typename TValue, const size_t ARRAY_SIZE>
229  ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<TValue*> rend(const TValue(&data)[ARRAY_SIZE])
230  {
231  return ETL_OR_STD::reverse_iterator<TValue*>(&data[0]);
232  }
233 
234  //*****************************************************************************
237  //*****************************************************************************
238  template<typename TValue, const size_t ARRAY_SIZE>
239  ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<const TValue*> crend(const TValue(&data)[ARRAY_SIZE])
240  {
241  return ETL_OR_STD::reverse_iterator<const TValue*>(&data[0]);
242  }
243 
249  template<typename TContainer>
250  ETL_CONSTEXPR typename TContainer::size_type size(const TContainer& container)
251  {
252  return container.size();
253  }
254 
259  template<typename TValue, const size_t ARRAY_SIZE>
260  ETL_CONSTEXPR size_t size(TValue(&)[ARRAY_SIZE])
261  {
262  return ARRAY_SIZE;
263  }
264 
272  template <typename T, const size_t ARRAY_SIZE>
273  char(&array_size(T(&array)[ARRAY_SIZE]))[ARRAY_SIZE];
274 }
275 
276 #if ETL_CPP11_SUPPORTED && !defined(ETL_FORCE_NO_ADVANCED_CPP)
277  #define ETL_ARRAY_SIZE(a) (etl::size(a))
278 #else
279  #define ETL_ARRAY_SIZE(a) sizeof(etl::array_size(a))
280 #endif
281 
282 #endif
283 
ETL_CONSTEXPR TContainer::reverse_iterator rbegin(const TContainer &container)
Definition: container.h:79
ETL_CONSTEXPR TContainer::const_iterator rend(const TContainer &container)
Definition: container.h:129
ETL_CONSTEXPR TContainer::const_iterator cbegin(const TContainer &container)
Definition: container.h:69
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition: container.h:49
ETL_CONSTEXPR TContainer::reverse_iterator crend(const TContainer &container)
Definition: container.h:139
ETL_CONSTEXPR TContainer::reverse_iterator crbegin(const TContainer &container)
Definition: container.h:89
ETL_CONSTEXPR TContainer::const_iterator cend(const TContainer &container)
Definition: container.h:119
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition: container.h:99
Definition: absolute.h:37