Embedded Template Library 1.0
Loading...
Searching...
No Matches
span.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) 2020 John Wellbelove
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_SPAN_INCLUDED
32#define ETL_SPAN_INCLUDED
33
34#include "platform.h"
35#include "iterator.h"
36#include "algorithm.h"
37#include "circular_iterator.h"
38#include "nullptr.h"
39#include "hash.h"
40#include "type_traits.h"
41#include "integral_limits.h"
42#include "memory.h"
43#include "array.h"
44#include "byte.h"
45#include "static_assert.h"
46
48
49#if ETL_USING_CPP20 && ETL_USING_STL
50 #include <span>
51#endif
52
55
56namespace etl
57{
58 //***************************************************************************
60 //***************************************************************************
61 template <typename T, size_t Extent = etl::dynamic_extent>
62 class span
63 {
64 public:
65
66 typedef T element_type;
67 typedef typename etl::remove_cv<T>::type value_type;
68 typedef size_t size_type;
69 typedef T& reference;
70 typedef const T& const_reference;
71 typedef T* pointer;
72 typedef const T* const_pointer;
73
74 typedef T* iterator;
75 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
76
79
80 static ETL_CONSTANT size_t extent = Extent;
81
82 //*************************************************************************
84 //*************************************************************************
85 template <typename TIterator, typename TSize>
86 ETL_CONSTEXPR explicit span(const TIterator begin_, const TSize /*size_*/) ETL_NOEXCEPT
87 : pbegin(etl::addressof(*begin_))
88 {
89 }
90
91 //*************************************************************************
93 //*************************************************************************
94 template <typename TIterator>
95 ETL_CONSTEXPR explicit span(const TIterator begin_, const TIterator /*end_*/)
96 : pbegin(etl::addressof(*begin_))
97 {
98 }
99
100 //*************************************************************************
102 //*************************************************************************
103 template<size_t Array_Size>
104 ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT
105 : pbegin(begin_)
106 {
107 }
108
109#if ETL_USING_CPP11
110 //*************************************************************************
113 //*************************************************************************
114 template <typename TContainer, typename = typename etl::enable_if<!etl::is_pointer<etl::remove_reference_t<TContainer>>::value &&
115 !etl::is_array<etl::remove_reference_t<TContainer>>::value&&
116 etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<typename etl::remove_reference_t<TContainer>::value_type>>::value, void>::type>
117 ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT
118 : pbegin(a.data())
119 {
120 }
121#else
122 //*************************************************************************
125 //*************************************************************************
126 template <typename TContainer>
129 etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT
130 : pbegin(a.data())
131 {
132 }
133
134 //*************************************************************************
137 //*************************************************************************
138 template <typename TContainer>
139 ETL_CONSTEXPR span(const TContainer& a, typename etl::enable_if<!etl::is_pointer<typename etl::remove_reference<TContainer>::type>::value &&
141 etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT
142 : pbegin(a.data())
143 {
144 }
145#endif
146
147 //*************************************************************************
149 //*************************************************************************
150 ETL_CONSTEXPR span(const span& other) ETL_NOEXCEPT
151 : pbegin(other.pbegin)
152 {
153 }
154
155 //*************************************************************************
157 //*************************************************************************
158 template <typename U, size_t N>
159 ETL_CONSTEXPR span(const etl::span<U, N>& other, typename etl::enable_if<(Extent == etl::dynamic_extent) || (N == etl::dynamic_extent) || (N == Extent), void>::type) ETL_NOEXCEPT
160 : pbegin(other.data())
161 {
162 }
163
164 //*************************************************************************
166 //*************************************************************************
167 ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
168 {
169 return *pbegin;
170 }
171
172 //*************************************************************************
174 //*************************************************************************
175 ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
176 {
177 return *((pbegin + Extent) - 1);
178 }
179
180 //*************************************************************************
182 //*************************************************************************
183 ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
184 {
185 return pbegin;
186 }
187
188 //*************************************************************************
190 //*************************************************************************
191 ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
192 {
193 return pbegin;
194 }
195
196 //*************************************************************************
198 //*************************************************************************
199 ETL_NODISCARD ETL_CONSTEXPR circular_iterator begin_circular() const ETL_NOEXCEPT
200 {
201 return circular_iterator(begin(), end());
202 }
203
204 //*************************************************************************
206 //*************************************************************************
207 ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
208 {
209 return (pbegin + Extent);
210 }
211
212 //*************************************************************************
213 // Returns an reverse iterator to the reverse beginning of the span.
214 //*************************************************************************
215 ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rbegin() const ETL_NOEXCEPT
216 {
217 return reverse_iterator((pbegin + Extent));
218 }
219
220 //*************************************************************************
222 //*************************************************************************
223 ETL_NODISCARD ETL_CONSTEXPR reverse_circular_iterator rbegin_circular() const ETL_NOEXCEPT
224 {
225 return reverse_circular_iterator(rbegin(), rend());
226 }
227
228 //*************************************************************************
230 //*************************************************************************
231 ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
232 {
233 return reverse_iterator(pbegin);
234 }
235
236 //*************************************************************************
238 //*************************************************************************
239 ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
240 {
241 return false;
242 }
243
244 //*************************************************************************
246 //*************************************************************************
247 ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
248 {
249 return Extent;
250 }
251
252 //*************************************************************************
254 //*************************************************************************
255 ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
256 {
257 return sizeof(element_type) * Extent;
258 }
259
260 //*************************************************************************
262 //*************************************************************************
263 ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
264 {
265 return size();
266 }
267
268 //*************************************************************************
270 //*************************************************************************
271 ETL_CONSTEXPR14 span& operator =(const span& other) ETL_NOEXCEPT
272 {
273 pbegin = other.pbegin;
274 return *this;
275 }
276
277 //*************************************************************************
279 //*************************************************************************
280 ETL_CONSTEXPR reference operator[](const size_t i) const
281 {
282 return pbegin[i];
283 }
284
285 //*************************************************************************
287 //*************************************************************************
288 template <size_t COUNT>
289 ETL_NODISCARD ETL_CONSTEXPR etl::span<element_type, COUNT> first() const ETL_NOEXCEPT
290 {
291 // If Extent is static, check that original span contains at least COUNT elements
292 ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) ? COUNT <= Extent : true, "Original span does not contain COUNT elements");
293
294 return etl::span<element_type, COUNT>(pbegin, pbegin + COUNT);
295 }
296
297 //*************************************************************************
299 //*************************************************************************
300 ETL_NODISCARD ETL_CONSTEXPR etl::span<element_type, etl::dynamic_extent> first(size_t count) const ETL_NOEXCEPT
301 {
302 return etl::span<element_type, etl::dynamic_extent>(pbegin, pbegin + count);
303 }
304
305 //*************************************************************************
307 //*************************************************************************
308 template <size_t COUNT>
309 ETL_NODISCARD ETL_CONSTEXPR etl::span<element_type, COUNT> last() const ETL_NOEXCEPT
310 {
311 // If Extent is static, check that original span contains at least COUNT elements
312 ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) ? COUNT <= Extent : true, "Original span does not contain COUNT elements");
313
314 return etl::span<element_type, COUNT>(pbegin + Extent - COUNT, (pbegin + Extent));
315 }
316
317 //*************************************************************************
319 //*************************************************************************
320 ETL_NODISCARD ETL_CONSTEXPR etl::span<element_type, etl::dynamic_extent> last(size_t count) const ETL_NOEXCEPT
321 {
322 return etl::span<element_type, etl::dynamic_extent>((pbegin + Extent) - count, (pbegin + Extent));
323 }
324
325#if ETL_USING_CPP11
326 //*************************************************************************
328 //*************************************************************************
329 template <size_t OFFSET, size_t COUNT = etl::dynamic_extent>
330 ETL_NODISCARD ETL_CONSTEXPR
331 etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET> subspan() const ETL_NOEXCEPT
332 {
333 // If Extent is static, check that OFFSET is within the original span
334 ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) ? OFFSET <= Extent : true, "OFFSET is not within the original span");
335
336 // If count is also static, check that OFFSET + COUNT is within the original span
337 ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (Extent - OFFSET) : true, "OFFSET + COUNT is not within the original span");
338
339 return (COUNT == etl::dynamic_extent) ? etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET>(pbegin + OFFSET, (pbegin + Extent))
340 : etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET>(pbegin + OFFSET, pbegin + OFFSET + COUNT);
341 }
342#else
343 //*************************************************************************
345 //*************************************************************************
346 template <size_t OFFSET, size_t COUNT>
347 etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET> subspan() const
348 {
349 // If Extent is static, check that OFFSET is within the original span
350 ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) ? OFFSET <= Extent : true, "OFFSET is not within the original span");
351
352 // If count is also static, check that OFFSET + COUNT is within the original span
353 ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (Extent - OFFSET) : true, "OFFSET + COUNT is not within the original span");
354
355 if (COUNT == etl::dynamic_extent)
356 {
357 return etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET)>(pbegin + OFFSET, (pbegin + Extent));
358 }
359 else
360 {
361 return etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET>(pbegin + OFFSET, pbegin + OFFSET + COUNT);
362 }
363 }
364#endif
365
366 //*************************************************************************
368 //*************************************************************************
369 ETL_NODISCARD ETL_CONSTEXPR etl::span<element_type, etl::dynamic_extent> subspan(size_t offset, size_t count = etl::dynamic_extent) const ETL_NOEXCEPT
370 {
371 return (count == etl::dynamic_extent) ? etl::span<element_type, etl::dynamic_extent>(pbegin + offset, (pbegin + Extent))
372 : etl::span<element_type, etl::dynamic_extent>(pbegin + offset, pbegin + offset + count);
373 }
374
375 private:
376
377 pointer pbegin;
378 };
379
380 //***************************************************************************
382 //***************************************************************************
383 template <typename T>
384 class span<T, etl::dynamic_extent>
385 {
386 public:
387
388 typedef T element_type;
389 typedef typename etl::remove_cv<T>::type value_type;
390 typedef size_t size_type;
391 typedef T& reference;
392 typedef const T& const_reference;
393 typedef T* pointer;
394 typedef const T* const_pointer;
395
396 typedef T* iterator;
397 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
398
401
402 static ETL_CONSTANT size_t extent = etl::dynamic_extent;
403
404 //*************************************************************************
406 //*************************************************************************
407 ETL_CONSTEXPR span() ETL_NOEXCEPT
408 : pbegin(ETL_NULLPTR)
409 , pend(ETL_NULLPTR)
410 {
411 }
412
413 //*************************************************************************
415 //*************************************************************************
416 template <typename TIterator, typename TSize>
417 ETL_CONSTEXPR span(const TIterator begin_, const TSize size_) ETL_NOEXCEPT
418 : pbegin(etl::addressof(*begin_))
419 , pend(etl::addressof(*begin_) + size_)
420 {
421 }
422
423 //*************************************************************************
425 //*************************************************************************
426 template <typename TIterator>
427 ETL_CONSTEXPR span(const TIterator begin_, const TIterator end_)
428 : pbegin(etl::addressof(*begin_))
429 , pend(etl::addressof(*begin_) + etl::distance(begin_, end_))
430 {
431 }
432
433 //*************************************************************************
435 //*************************************************************************
436 template<size_t Array_Size>
437 ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT
438 : pbegin(begin_)
439 , pend(begin_ + Array_Size)
440 {
441 }
442
443#if ETL_USING_CPP11
444 //*************************************************************************
447 //*************************************************************************
448 template <typename TContainer, typename = typename etl::enable_if<!etl::is_pointer<etl::remove_reference_t<TContainer>>::value &&
449 !etl::is_array<etl::remove_reference_t<TContainer>>::value &&
450 etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<typename etl::remove_reference_t<TContainer>::value_type>>::value, void>::type>
451 ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT
452 : pbegin(a.data())
453 , pend(a.data() + a.size())
454 {
455 }
456#else
457 //*************************************************************************
460 //*************************************************************************
461 template <typename TContainer>
464 etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT
465 : pbegin(a.data())
466 , pend(a.data() + a.size())
467 {
468 }
469
470 //*************************************************************************
473 //*************************************************************************
474 template <typename TContainer>
475 ETL_CONSTEXPR span(const TContainer& a, typename etl::enable_if<!etl::is_pointer<typename etl::remove_reference<TContainer>::type>::value &&
477 etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT
478 : pbegin(a.data())
479 , pend(a.data() + a.size())
480 {
481 }
482#endif
483
484 //*************************************************************************
486 //*************************************************************************
487 ETL_CONSTEXPR span(const span& other) ETL_NOEXCEPT
488 : pbegin(other.pbegin)
489 , pend(other.pend)
490 {
491 }
492
493 //*************************************************************************
495 //*************************************************************************
496 template <typename U, size_t N>
497 ETL_CONSTEXPR span(const etl::span<U, N>& other) ETL_NOEXCEPT
498 : pbegin(other.data())
499 , pend(other.data() + other.size())
500 {
501 }
502
503 //*************************************************************************
505 //*************************************************************************
506 ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
507 {
508 return *pbegin;
509 }
510
511 //*************************************************************************
513 //*************************************************************************
514 ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
515 {
516 return *(pend - 1);
517 }
518
519 //*************************************************************************
521 //*************************************************************************
522 ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
523 {
524 return pbegin;
525 }
526
527 //*************************************************************************
529 //*************************************************************************
530 ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
531 {
532 return pbegin;
533 }
534
535 //*************************************************************************
537 //*************************************************************************
538 ETL_NODISCARD ETL_CONSTEXPR circular_iterator begin_circular() const ETL_NOEXCEPT
539 {
540 return circular_iterator(begin(), end());
541 }
542
543 //*************************************************************************
545 //*************************************************************************
546 ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
547 {
548 return pend;
549 }
550
551 //*************************************************************************
552 // Returns an reverse iterator to the reverse beginning of the span.
553 //*************************************************************************
554 ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rbegin() const ETL_NOEXCEPT
555 {
556 return reverse_iterator(pend);
557 }
558
559 //*************************************************************************
561 //*************************************************************************
562 ETL_NODISCARD ETL_CONSTEXPR reverse_circular_iterator rbegin_circular() const ETL_NOEXCEPT
563 {
564 return reverse_circular_iterator(rbegin(), rend());
565 }
566
567 //*************************************************************************
569 //*************************************************************************
570 ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
571 {
572 return reverse_iterator(pbegin);
573 }
574
575 //*************************************************************************
577 //*************************************************************************
578 ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
579 {
580 return (pbegin == pend);
581 }
582
583 //*************************************************************************
585 //*************************************************************************
586 ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
587 {
588 return (pend - pbegin);
589 }
590
591 //*************************************************************************
593 //*************************************************************************
594 ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
595 {
596 return sizeof(element_type) * (pend - pbegin);
597 }
598
599 //*************************************************************************
601 //*************************************************************************
602 ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
603 {
604 return size();
605 }
606
607 //*************************************************************************
609 //*************************************************************************
610 ETL_CONSTEXPR14 span& operator =(const span& other) ETL_NOEXCEPT
611 {
612 pbegin = other.pbegin;
613 pend = other.pend;
614 return *this;
615 }
616
617 //*************************************************************************
619 //*************************************************************************
620 ETL_CONSTEXPR reference operator[](const size_t i) const
621 {
622 return pbegin[i];
623 }
624
625 //*************************************************************************
627 //*************************************************************************
628 template <size_t COUNT>
629 ETL_NODISCARD ETL_CONSTEXPR etl::span<element_type, COUNT> first() const ETL_NOEXCEPT
630 {
631 return etl::span<element_type, COUNT>(pbegin, pbegin + COUNT);
632 }
633
634 //*************************************************************************
636 //*************************************************************************
637 ETL_NODISCARD ETL_CONSTEXPR etl::span<element_type, etl::dynamic_extent> first(size_t count) const ETL_NOEXCEPT
638 {
639 return etl::span<element_type, etl::dynamic_extent>(pbegin, pbegin + count);
640 }
641
642 //*************************************************************************
644 //*************************************************************************
645 template <size_t COUNT>
646 ETL_NODISCARD ETL_CONSTEXPR etl::span<element_type, COUNT> last() const ETL_NOEXCEPT
647 {
648 return etl::span<element_type, COUNT>(pend - COUNT, pend);
649 }
650
651 //*************************************************************************
653 //*************************************************************************
654 ETL_NODISCARD ETL_CONSTEXPR etl::span<element_type, etl::dynamic_extent> last(size_t count) const ETL_NOEXCEPT
655 {
656 return etl::span<element_type, etl::dynamic_extent>(pend - count, pend);
657 }
658
659#if ETL_USING_CPP11
660 //*************************************************************************
662 //*************************************************************************
663 template <size_t OFFSET, size_t COUNT = etl::dynamic_extent>
664 ETL_NODISCARD ETL_CONSTEXPR
666 {
668 : etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : etl::dynamic_extent>(pbegin + OFFSET, pbegin + OFFSET + COUNT);
669 }
670#else
671 //*************************************************************************
673 //*************************************************************************
674 template <size_t OFFSET, size_t COUNT>
686#endif
687
688 //*************************************************************************
690 //*************************************************************************
691 ETL_NODISCARD ETL_CONSTEXPR14 etl::span<element_type, etl::dynamic_extent> subspan(size_t offset, size_t count = etl::dynamic_extent) const ETL_NOEXCEPT
692 {
693 return (count == etl::dynamic_extent) ? etl::span<element_type, etl::dynamic_extent>(pbegin + offset, pend)
694 : etl::span<element_type, etl::dynamic_extent>(pbegin + offset, pbegin + offset + count);
695 }
696
697 private:
698
699 pointer pbegin;
700 pointer pend;
701 };
702
703 template <typename T, size_t Extent>
704 ETL_CONSTANT size_t span<T, Extent>::extent;
705
706 template <typename T>
707 ETL_CONSTANT size_t span<T, etl::dynamic_extent>::extent;
708
709 //*************************************************************************
711 //*************************************************************************
712 template <typename T1, size_t N1, typename T2, size_t N2>
713 ETL_NODISCARD
714 ETL_CONSTEXPR
717 {
718 return (lhs.begin() == rhs.begin()) && (lhs.size() == rhs.size());
719 }
720
721 //*************************************************************************
723 //*************************************************************************
724 template <typename T1, size_t N1, typename T2, size_t N2>
725 ETL_NODISCARD
726 ETL_CONSTEXPR
727 bool operator !=(const etl::span<T1, N1>& lhs, const etl::span<T2, N2>& rhs) ETL_NOEXCEPT
728 {
729 return !(lhs == rhs);
730 }
731
732 //*************************************************************************
739 //*************************************************************************
740 template <typename T1, size_t N1, typename T2, size_t N2>
743 {
744 return (lhs.empty() && rhs.empty()) ||
745 ((lhs.begin() == rhs.begin()) && (lhs.size() == rhs.size())) ||
746 etl::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
747 }
748
749 //*************************************************************************
751 //*************************************************************************
752#if ETL_USING_CPP17
753 template <typename TIterator>
754 span(const TIterator begin_, const TIterator end_)
755 ->span<etl::remove_pointer_t<TIterator>, etl::dynamic_extent>;
756
757 template <typename TIterator, typename TSize>
758 span(const TIterator begin_, const TSize size_)
759 ->span<etl::remove_pointer_t<TIterator>, etl::dynamic_extent>;
760
761 template <typename T, size_t N>
762 span(T(&)[N])
763 -> span<T, N>;
764
765 template <typename T, size_t N>
766 span(etl::array<T, N>&)
767 -> span<T, N>;
768
769 template <typename T, size_t N>
770 span(const etl::array<T, N>&)
771 -> span<const T, N>;
772
773#if ETL_USING_STL && ETL_USING_CPP11
774 template <typename T, size_t N>
775 span(std::array<T, N>&)
776 ->span<T, N>;
777
778 template <typename T, size_t N>
779 span(const std::array<T, N>&)
780 ->span<const T, N>;
781#endif
782#endif
783
784 //*************************************************************************
786 //*************************************************************************
787#if ETL_USING_8BIT_TYPES
788 template <typename T, size_t Extent>
789 struct hash<etl::span<T, Extent> >
790 {
791 size_t operator()(const etl::span<T>& view) const
792 {
793 return etl::private_hash::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(view.data()),
794 reinterpret_cast<const uint8_t*>(view.data() + view.size()));
795 }
796 };
797#endif
798
799 //*************************************************************************
801 //*************************************************************************
802 template <class T, size_t N>
803 span<const byte, (N == etl::dynamic_extent) ? (etl::dynamic_extent) : (N * sizeof(T))>
804 as_bytes(span<T, N> s) ETL_NOEXCEPT
805 {
806 return span<const byte, (N == etl::dynamic_extent) ? (etl::dynamic_extent) : (N * sizeof(T))>(reinterpret_cast<byte*>(s.data()), s.size_bytes());
807 }
808
809 //*************************************************************************
811 //*************************************************************************
812 template <class T, size_t N>
813 span<byte, (N == etl::dynamic_extent) ? (etl::dynamic_extent) : (N * sizeof(T))>
815 {
816 ETL_STATIC_ASSERT(!etl::is_const<T>::value, "span<T> must be of non-const type");
817 return span<byte, (N == etl::dynamic_extent) ? (etl::dynamic_extent) : (N * sizeof(T))>(reinterpret_cast<byte*>(s.data()), s.size_bytes());
818 }
819}
820
821#endif
Definition iterator.h:228
ETL_NODISCARD ETL_CONSTEXPR circular_iterator begin_circular() const ETL_NOEXCEPT
Returns a circular iterator to the beginning of the span.
Definition span.h:538
ETL_CONSTEXPR span(const span &other) ETL_NOEXCEPT
Copy constructor.
Definition span.h:487
ETL_CONSTEXPR span() ETL_NOEXCEPT
Default constructor.
Definition span.h:407
etl::span< element_type, COUNT !=etl::dynamic_extent ? COUNT :etl::dynamic_extent > subspan() const
Obtains a span that is a view from OFFSET over the next COUNT elements of this span.
Definition span.h:675
ETL_NODISCARD ETL_CONSTEXPR reverse_circular_iterator rbegin_circular() const ETL_NOEXCEPT
Returns a reverse circular iterator to the end of the span.
Definition span.h:562
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, COUNT > first() const ETL_NOEXCEPT
Obtains a span that is a view over the first COUNT elements of this span.
Definition span.h:629
ETL_CONSTEXPR span(TContainer &a, typename etl::enable_if<!etl::is_pointer< typename etl::remove_reference< TContainer >::type >::value &&!etl::is_array< TContainer >::value &&etl::is_same< typename etl::remove_cv< T >::type, typename etl::remove_cv< typename etl::remove_reference< TContainer >::type::value_type >::type >::value, void >::type *=0) ETL_NOEXCEPT
Definition span.h:462
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the span.
Definition span.h:586
ETL_CONSTEXPR span(const etl::span< U, N > &other) ETL_NOEXCEPT
Copy constructor.
Definition span.h:497
ETL_NODISCARD ETL_CONSTEXPR14 etl::span< element_type, etl::dynamic_extent > subspan(size_t offset, size_t count=etl::dynamic_extent) const ETL_NOEXCEPT
Obtains a span that is a view from 'offset' over the next 'count' elements of this span.
Definition span.h:691
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the span size is zero.
Definition span.h:578
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, COUNT > last() const ETL_NOEXCEPT
Obtains a span that is a view over the last COUNT elements of this span.
Definition span.h:646
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, etl::dynamic_extent > first(size_t count) const ETL_NOEXCEPT
Obtains a span that is a view over the first count elements of this span.
Definition span.h:637
ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
Returns a reference to the last element.
Definition span.h:514
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, etl::dynamic_extent > last(size_t count) const ETL_NOEXCEPT
Obtains a span that is a view over the last count elements of this span.
Definition span.h:654
ETL_CONSTEXPR reference operator[](const size_t i) const
Returns a reference to the indexed value.
Definition span.h:620
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the span.
Definition span.h:530
ETL_CONSTEXPR span(const TContainer &a, typename etl::enable_if<!etl::is_pointer< typename etl::remove_reference< TContainer >::type >::value &&!etl::is_array< TContainer >::value &&etl::is_same< typename etl::remove_cv< T >::type, typename etl::remove_cv< typename etl::remove_reference< TContainer >::type::value_type >::type >::value, void >::type *=0) ETL_NOEXCEPT
Definition span.h:475
ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
Returns a reference to the first element.
Definition span.h:506
ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT
Construct from C array.
Definition span.h:437
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the span.
Definition span.h:546
ETL_CONSTEXPR span(const TIterator begin_, const TIterator end_)
Construct from iterators.
Definition span.h:427
ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
Returns a pointer to the first element of the internal storage.
Definition span.h:522
ETL_CONSTEXPR span(const TIterator begin_, const TSize size_) ETL_NOEXCEPT
Construct from pointer + size.
Definition span.h:417
ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
Returns a reverse iterator to the end of the span.
Definition span.h:570
ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
Returns the maximum possible size of the span.
Definition span.h:602
ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
Returns the size of the span in bytes.
Definition span.h:594
Span - Fixed Extent.
Definition span.h:63
ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
Returns a reverse iterator to the end of the span.
Definition span.h:231
ETL_NODISCARD ETL_CONSTEXPR circular_iterator begin_circular() const ETL_NOEXCEPT
Returns a circular iterator to the beginning of the span.
Definition span.h:199
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, COUNT > last() const ETL_NOEXCEPT
Obtains a span that is a view over the last COUNT elements of this span.
Definition span.h:309
ETL_CONSTEXPR span(const span &other) ETL_NOEXCEPT
Copy constructor.
Definition span.h:150
etl::span< element_type, COUNT !=etl::dynamic_extent ? COUNT :Extent - OFFSET > subspan() const
Obtains a span that is a view from OFFSET over the next COUNT elements of this span.
Definition span.h:347
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, etl::dynamic_extent > first(size_t count) const ETL_NOEXCEPT
Obtains a span that is a view over the first count elements of this span.
Definition span.h:300
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, etl::dynamic_extent > subspan(size_t offset, size_t count=etl::dynamic_extent) const ETL_NOEXCEPT
Obtains a span that is a view from 'offset' over the next 'count' elements of this span.
Definition span.h:369
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, etl::dynamic_extent > last(size_t count) const ETL_NOEXCEPT
Obtains a span that is a view over the last count elements of this span.
Definition span.h:320
ETL_NODISCARD ETL_CONSTEXPR reverse_circular_iterator rbegin_circular() const ETL_NOEXCEPT
Returns a reverse circular iterator to the end of the span.
Definition span.h:223
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the span.
Definition span.h:191
ETL_CONSTEXPR span(const etl::span< U, N > &other, typename etl::enable_if<(Extent==etl::dynamic_extent)||(N==etl::dynamic_extent)||(N==Extent), void >::type) ETL_NOEXCEPT
Copy constructor.
Definition span.h:159
ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
Returns the size of the span in bytes.
Definition span.h:255
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the span size is zero.
Definition span.h:239
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, COUNT > first() const ETL_NOEXCEPT
Obtains a span that is a view over the first COUNT elements of this span.
Definition span.h:289
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the span.
Definition span.h:247
ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
Returns a reference to the last element.
Definition span.h:175
ETL_CONSTEXPR14 span & operator=(const span &other) ETL_NOEXCEPT
Assign from a span.
Definition span.h:271
ETL_CONSTEXPR span(const TIterator begin_, const TIterator)
Construct from iterators.
Definition span.h:95
ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT
Construct from C array.
Definition span.h:104
ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
Returns a pointer to the first element of the internal storage.
Definition span.h:183
ETL_CONSTEXPR span(const TContainer &a, typename etl::enable_if<!etl::is_pointer< typename etl::remove_reference< TContainer >::type >::value &&!etl::is_array< TContainer >::value &&etl::is_same< typename etl::remove_cv< T >::type, typename etl::remove_cv< typename etl::remove_reference< TContainer >::type::value_type >::type >::value, void >::type *=0) ETL_NOEXCEPT
Definition span.h:139
ETL_CONSTEXPR span(const TIterator begin_, const TSize) ETL_NOEXCEPT
Construct from iterators + size.
Definition span.h:86
ETL_CONSTEXPR reference operator[](const size_t i) const
Returns a reference to the indexed value.
Definition span.h:280
span(TContainer &a, typename etl::enable_if<!etl::is_pointer< typename etl::remove_reference< TContainer >::type >::value &&!etl::is_array< TContainer >::value &&etl::is_same< typename etl::remove_cv< T >::type, typename etl::remove_cv< typename etl::remove_reference< TContainer >::type::value_type >::type >::value, void >::type *=0) ETL_NOEXCEPT
Definition span.h:127
ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
Returns the maximum possible size of the span.
Definition span.h:263
ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
Returns a reference to the first element.
Definition span.h:167
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the span.
Definition span.h:207
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
enable_if
Definition type_traits_generator.h:1191
extent
Definition type_traits_generator.h:1202
is_array
Definition type_traits_generator.h:1091
is_const
Definition type_traits_generator.h:908
is_pointer
Definition type_traits_generator.h:1101
is_same
Definition type_traits_generator.h:1041
remove_cv
Definition type_traits_generator.h:968
remove_reference
Definition type_traits_generator.h:878
bitset_ext
Definition absolute.h:38
span< byte,(N==etl::dynamic_extent) ?(etl::dynamic_extent) :(N *sizeof(T))> as_writable_bytes(span< T, N > s) ETL_NOEXCEPT
Obtains a view to the byte representation of the elements of the span s.
Definition span.h:814
span< const byte,(N==etl::dynamic_extent) ?(etl::dynamic_extent) :(N *sizeof(T))> as_bytes(span< T, N > s) ETL_NOEXCEPT
Template deduction guides.
Definition span.h:804
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:654
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:642
pair holds two objects of arbitrary type
Definition utility.h:164