34#ifndef ETL_POLY_SPAN_INCLUDED
35#define ETL_POLY_SPAN_INCLUDED
48#if ETL_USING_STL && ETL_USING_CPP11
57 template <
typename U,
size_t Extent>
60 namespace private_poly_span
65 template <
typename TBase>
70 template <
typename U,
size_t Extent>
73 template <
typename UBase>
74 friend class const_iterator;
80 typedef ETL_OR_STD::random_access_iterator_tag iterator_category;
92 , element_size(
other.element_size)
100 element_size =
rhs.element_size;
120 ptr =
reinterpret_cast<pointer>(
reinterpret_cast<char*
>(ptr) + element_size);
128 ptr =
reinterpret_cast<pointer>(
reinterpret_cast<char*
>(ptr) + element_size);
135 ptr =
reinterpret_cast<pointer>(
reinterpret_cast<char*
>(ptr) - element_size);
143 ptr =
reinterpret_cast<pointer>(
reinterpret_cast<char*
>(ptr) - element_size);
150 ptr =
reinterpret_cast<pointer>(
reinterpret_cast<char*
>(ptr) + (offset * difference_type(element_size)));
157 ptr =
reinterpret_cast<pointer>(
reinterpret_cast<char*
>(ptr) - (offset * difference_type(element_size)));
164 return (
lhs.ptr ==
rhs.ptr) && (
lhs.element_size ==
rhs.element_size);
252 template <
typename TBase,
size_t Extent = etl::dynamic_extent>
266 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
270 template <
typename UBase,
size_t UExtent>
277 : pbegin(ETL_NULLPTR)
285 template <
typename TIterator,
typename TSize>
288 , element_size(
sizeof(
typename etl::iterator_traits<TIterator>::value_type))
290 typedef typename etl::iterator_traits<TIterator>::value_type
data_type;
292 ETL_STATIC_ASSERT((
etl::is_same<ETL_OR_STD::random_access_iterator_tag,
typename etl::iterator_traits<TIterator>::iterator_category>::value),
"Not a random access iterator");
299 template <
typename TIterator>
304 typedef typename etl::iterator_traits<TIterator>::value_type
data_type;
305 typedef typename etl::iterator_traits<TIterator>::iterator_category iterator_category;
314 template<
typename U,
size_t N>
317 , element_size(
sizeof(
U))
319 ETL_STATIC_ASSERT(
N <=
Extent,
"Array data overflow");
326 template <
typename U,
size_t N>
329 , element_size(
sizeof(
U))
331 ETL_STATIC_ASSERT(
N <=
Extent,
"Array data overflow");
338 template <
typename U,
size_t N>
341 , element_size(
sizeof(
U))
343 ETL_STATIC_ASSERT(
N <=
Extent,
"Array data overflow");
347#if ETL_USING_STL && ETL_USING_CPP11
351 template <
typename U,
size_t N>
352 ETL_CONSTEXPR
poly_span(std::array<U, N>& a) ETL_NOEXCEPT
354 , element_size(
sizeof(
U))
356 ETL_STATIC_ASSERT(
N <=
Extent,
"Array data overflow");
363 template <
typename U,
size_t N>
364 ETL_CONSTEXPR poly_span(
const std::array<U, N>& a) ETL_NOEXCEPT
366 , element_size(
sizeof(U))
368 ETL_STATIC_ASSERT(N <= Extent,
"Array data overflow");
377 : pbegin(
other.pbegin)
378 , element_size(
other.element_size)
385 template <
typename UBase>
387 : pbegin(
other.pbegin)
388 , element_size(
other.element_size)
405 return *element_at(
Extent - 1U);
421 return iterator(pbegin, 0
U, element_size);
443 ETL_CONSTEXPR reverse_iterator
rend()
const ETL_NOEXCEPT
445 return reverse_iterator(
begin());
459 ETL_NODISCARD ETL_CONSTEXPR
size_t size()
const ETL_NOEXCEPT
477 return Extent * element_size;
485 pbegin =
other.pbegin;
486 element_size =
other.element_size;
493 template <
typename UBase>
496 pbegin =
other.pbegin;
497 element_size =
other.element_size;
506 return *element_at(
i);
512 template <
size_t COUNT>
529 template <
size_t COUNT>
547 template <
size_t OFFSET,
size_t COUNT = etl::dynamic_extent>
557 template <
size_t OFFSET,
size_t COUNT>
560 if (
COUNT == etl::dynamic_extent)
583 template <
typename TFrom>
592 pointer element_at(
size_t index)
const ETL_NOEXCEPT
595 return reinterpret_cast<pointer>(base + (index * element_size));
614 template <
typename TBase,
size_t Extent>
615 ETL_CONSTANT
size_t poly_span<TBase, Extent>::extent;
620 template <
typename TBase>
633 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
635 static ETL_CONSTANT
size_t extent = etl::dynamic_extent;
637 template <
typename UBase,
size_t UExtent>
644 : pbegin(ETL_NULLPTR)
653 template <
typename TIterator,
typename TSize>
656 , element_size(
sizeof(
typename etl::iterator_traits<TIterator>::value_type))
659 typedef typename etl::iterator_traits<TIterator>::value_type
data_type;
660 typedef typename etl::iterator_traits<TIterator>::iterator_category iterator_category;
669 template <
typename TIterator>
675 typedef typename etl::iterator_traits<TIterator>::value_type
data_type;
676 typedef typename etl::iterator_traits<TIterator>::iterator_category iterator_category;
685 template<
typename U,
size_t N>
688 , element_size(
sizeof(
U))
697 template <
typename U,
size_t N>
700 , element_size(
sizeof(
U))
709 template <
typename U,
size_t N>
712 , element_size(
sizeof(
U))
718#if ETL_USING_STL && ETL_USING_CPP11
722 template <
typename U,
size_t N>
723 ETL_CONSTEXPR
poly_span(std::array<U, N>& a) ETL_NOEXCEPT
725 , element_size(
sizeof(
U))
734 template <
typename U,
size_t N>
735 ETL_CONSTEXPR poly_span(
const std::array<U, N>& a) ETL_NOEXCEPT
737 , element_size(
sizeof(U))
748 : pbegin(
other.pbegin)
749 , element_size(
other.element_size)
750 , span_extent(
other.span_extent)
757 template <
typename UBase>
759 : pbegin(
other.pbegin)
760 , element_size(
other.element_size)
761 , span_extent(
other.span_extent)
778 return *element_at(span_extent - 1U);
794 return iterator(pbegin, 0
U, element_size);
802 return iterator(pbegin, span_extent, element_size);
816 ETL_NODISCARD ETL_CONSTEXPR reverse_iterator
rend()
const ETL_NOEXCEPT
818 return reverse_iterator(
begin());
826 return (span_extent == 0);
832 ETL_NODISCARD ETL_CONSTEXPR
size_t size()
const ETL_NOEXCEPT
850 return element_size * span_extent;
858 pbegin =
other.pbegin;
859 element_size =
other.element_size;
860 span_extent =
other.span_extent;
867 template <
typename UBase>
870 pbegin =
other.pbegin;
871 element_size =
other.element_size;
872 span_extent =
other.span_extent;
881 return *element_at(
i);
887 template <
size_t COUNT>
904 template <
size_t COUNT>
922 template <
size_t OFFSET,
size_t COUNT = etl::dynamic_extent>
932 template <
size_t OFFSET,
size_t COUNT>
935 if (
COUNT == etl::dynamic_extent)
970 template <
typename TFrom>
976 typedef typename char_ptr_type<TBase>::type char_ptr_t;
979 pointer element_at(
size_t index)
const ETL_NOEXCEPT
981 char_ptr_t base =
reinterpret_cast<char_ptr_t
>(pbegin);
982 return reinterpret_cast<pointer
>(base + (index * element_size));
990 template <
typename TBase>
991 ETL_CONSTANT
size_t poly_span<TBase, etl::dynamic_extent>::extent;
997 template <
typename TIterator>
998 poly_span(
const TIterator begin_,
const TIterator end_)
1001 template <
typename TIterator,
typename TSize>
1002 poly_span(
const TIterator begin_,
const TSize size_)
1005 template <
typename T,
size_t N>
1009 template <
typename T,
size_t N>
1013 template <
typename T,
size_t N>
1015 ->poly_span<
const T, N>;
1018 template <
typename T,
size_t N>
1019 poly_span(std::array<T, N>&)
1022 template <
typename T,
size_t N>
1023 poly_span(
const std::array<T, N>&)
1024 ->poly_span<
const T, N>;
1031#if ETL_USING_8BIT_TYPES
1032 template <
typename TBase,
size_t Extent>
1033 struct hash<
etl::poly_span<TBase, Extent> >
1037 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(view.data()),
1038 reinterpret_cast<const uint8_t*
>(view.data() + view.size()));
ETL_CONSTEXPR poly_span(const TIterator begin_, const TSize size_) ETL_NOEXCEPT
Construct from iterator + size.
Definition poly_span.h:654
ETL_CONSTEXPR poly_span() ETL_NOEXCEPT
Default constructor.
Definition poly_span.h:643
ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
Returns a reference to the first element.
Definition poly_span.h:768
ETL_NODISCARD ETL_CONSTEXPR etl::poly_span< element_type, etl::dynamic_extent > last(size_t count) const ETL_NOEXCEPT
Obtains a poly_span that is a view over the last count elements of this poly_span.
Definition poly_span.h:913
ETL_NODISCARD ETL_CONSTEXPR etl::poly_span< element_type, COUNT > last() const ETL_NOEXCEPT
Obtains a poly_span that is a view over the last COUNT elements of this poly_span.
Definition poly_span.h:905
ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
Returns a reverse iterator to the end of the poly_span.
Definition poly_span.h:816
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the poly_span.
Definition poly_span.h:792
ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
Returns a pointer to the first element of the internal storage.
Definition poly_span.h:784
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the poly_span.
Definition poly_span.h:832
ETL_NODISCARD ETL_CONSTEXPR etl::poly_span< element_type, etl::dynamic_extent > subspan(size_t offset, size_t count=etl::dynamic_extent) const ETL_NOEXCEPT
Obtains a poly_span that is a view from 'offset' over the next 'count' elements of this poly_span.
Definition poly_span.h:949
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the poly_span size is zero.
Definition poly_span.h:824
ETL_NODISCARD ETL_CONSTEXPR size_t size_of_element() const ETL_NOEXCEPT
Returns the size of the type stored in the poly_span.
Definition poly_span.h:840
ETL_NODISCARD ETL_CONSTEXPR etl::poly_span< element_type, COUNT > first() const ETL_NOEXCEPT
Obtains a poly_span that is a view over the first COUNT elements of this poly_span.
Definition poly_span.h:888
ETL_CONSTEXPR poly_span(etl::array< U, N > &a) ETL_NOEXCEPT
Construct from etl::array.
Definition poly_span.h:698
poly_span(TBase *pbegin_, size_t offset_, size_t extent_, size_t element_size_) ETL_NOEXCEPT
Construct from iterator + offset + size + element size.
Definition poly_span.h:960
ETL_CONSTEXPR poly_span(const etl::array< U, N > &a) ETL_NOEXCEPT
Construct from etl::array.
Definition poly_span.h:710
ETL_CONSTEXPR poly_span(const TIterator begin_, const TIterator end_)
Construct from iterators.
Definition poly_span.h:670
ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
Returns the size of the poly_span in bytes.
Definition poly_span.h:848
ETL_CONSTEXPR poly_span(const poly_span< TBase, etl::dynamic_extent > &other) ETL_NOEXCEPT
Copy constructor.
Definition poly_span.h:747
ETL_CONSTEXPR reference operator[](size_t i) const
Returns a reference to the indexed value.
Definition poly_span.h:879
ETL_CONSTEXPR poly_span(U(&begin_)[N]) ETL_NOEXCEPT
Construct from C array.
Definition poly_span.h:686
ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
Returns a reference to the last element.
Definition poly_span.h:776
ETL_CONSTEXPR poly_span(const poly_span< UBase, etl::dynamic_extent > &other) ETL_NOEXCEPT
Copy constructor.
Definition poly_span.h:758
ETL_NODISCARD ETL_CONSTEXPR etl::poly_span< element_type, etl::dynamic_extent > first(size_t count) const ETL_NOEXCEPT
Obtains a poly_span that is a view over the first count elements of this poly_span.
Definition poly_span.h:896
etl::poly_span< element_type, COUNT !=etl::dynamic_extent ? COUNT :etl::dynamic_extent > subspan() const
Obtains a poly_span that is a view from OFFSET over the next COUNT elements of this poly_span.
Definition poly_span.h:933
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the poly_span.
Definition poly_span.h:800
Poly Span - Fixed Extent.
Definition poly_span.h:254
ETL_NODISCARD ETL_CONSTEXPR size_t size_of_element() const ETL_NOEXCEPT
Returns the size of the type stored in the poly_span.
Definition poly_span.h:467
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the poly_span.
Definition poly_span.h:427
ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
Returns a reverse iterator to the end of the poly_span.
Definition poly_span.h:443
ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
Returns a pointer to the first element of the internal storage.
Definition poly_span.h:411
poly_span(TBase *pbegin_, size_t offset_, size_t, size_t element_size_) ETL_NOEXCEPT
Definition poly_span.h:602
ETL_CONSTEXPR14 poly_span & operator=(const poly_span &other) ETL_NOEXCEPT
Assign from a poly_span.
Definition poly_span.h:483
ETL_CONSTEXPR poly_span(U(&begin_)[N]) ETL_NOEXCEPT
Construct from C array.
Definition poly_span.h:315
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the poly_span size is zero.
Definition poly_span.h:451
ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
Returns a reference to the first element.
Definition poly_span.h:395
ETL_CONSTEXPR poly_span(etl::array< U, N > &a) ETL_NOEXCEPT
Construct from etl::array.
Definition poly_span.h:327
ETL_NODISCARD ETL_CONSTEXPR etl::poly_span< element_type, etl::dynamic_extent > subspan(size_t offset, size_t count=etl::dynamic_extent) const ETL_NOEXCEPT
Obtains a poly_span that is a view from 'offset' over the next 'count' elements of this poly_span.
Definition poly_span.h:574
ETL_CONSTEXPR poly_span(const etl::array< U, N > &a) ETL_NOEXCEPT
Construct from etl::array.
Definition poly_span.h:339
ETL_CONSTEXPR poly_span() ETL_NOEXCEPT
Default constructor.
Definition poly_span.h:276
ETL_NODISCARD ETL_CONSTEXPR etl::poly_span< element_type, etl::dynamic_extent > first(size_t count) const
Obtains a poly_span that is a view over the first count elements of this poly_span.
Definition poly_span.h:521
ETL_CONSTEXPR poly_span(const TIterator begin_, const TSize) ETL_NOEXCEPT
Construct from iterator + size.
Definition poly_span.h:286
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the poly_span.
Definition poly_span.h:419
etl::poly_span< element_type, COUNT !=etl::dynamic_extent ? COUNT :Extent - OFFSET > subspan() const
Obtains a poly_span that is a view from OFFSET over the next COUNT elements of this poly_span.
Definition poly_span.h:558
ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
Returns a reference to the last element.
Definition poly_span.h:403
ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
Returns the size of the poly_span in bytes.
Definition poly_span.h:475
ETL_NODISCARD ETL_CONSTEXPR etl::poly_span< element_type, COUNT > last() const ETL_NOEXCEPT
Obtains a poly_span that is a view over the last COUNT elements of this poly_span.
Definition poly_span.h:530
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the poly_span.
Definition poly_span.h:459
ETL_CONSTEXPR poly_span(const poly_span< TBase, Extent > &other) ETL_NOEXCEPT
Copy constructor.
Definition poly_span.h:376
ETL_NODISCARD ETL_CONSTEXPR etl::poly_span< element_type, etl::dynamic_extent > last(size_t count) const ETL_NOEXCEPT
Obtains a poly_span that is a view over the last count elements of this poly_span.
Definition poly_span.h:538
ETL_CONSTEXPR reference operator[](size_t i) const
Returns a reference to the indexed value.
Definition poly_span.h:504
ETL_CONSTEXPR poly_span(const poly_span< UBase, Extent > &other) ETL_NOEXCEPT
Copy constructor.
Definition poly_span.h:386
ETL_CONSTEXPR poly_span(const TIterator begin_, const TIterator)
Construct from iterators.
Definition poly_span.h:300
ETL_NODISCARD ETL_CONSTEXPR etl::poly_span< element_type, COUNT > first() const ETL_NOEXCEPT
Obtains a poly_span that is a view over the first COUNT elements of this poly_span.
Definition poly_span.h:513
Definition poly_span.h:67
Definition iterator.h:228
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:968
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
extent
Definition type_traits_generator.h:1197
is_base_of
Definition type_traits_generator.h:1247
is_same
Definition type_traits_generator.h:1036
bitset_ext
Definition absolute.h:38
pair holds two objects of arbitrary type
Definition utility.h:164
Definition poly_span.h:585