31#ifndef ETL_ARRAY_VIEW_INCLUDED
32#define ETL_ARRAY_VIEW_INCLUDED
45#if ETL_USING_STL && ETL_USING_CPP11
62 array_view_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
63 :
exception(reason_, file_name_, line_number_)
72 class array_view_bounds :
public array_view_exception
76 array_view_bounds(string_type file_name_, numeric_type line_number_)
77 : array_view_exception(ETL_ERROR_TEXT(
"array_view:bounds", ETL_ARRAY_VIEW_FILE_ID
"A"), file_name_, line_number_)
86 class array_view_uninitialised :
public array_view_exception
90 array_view_uninitialised(string_type file_name_, numeric_type line_number_)
91 : array_view_exception(ETL_ERROR_TEXT(
"array_view:uninitialised", ETL_ARRAY_VIEW_FILE_ID
"B"), file_name_, line_number_)
104 typedef T value_type;
105 typedef size_t size_type;
106 typedef const T& const_reference;
107 typedef const T* const_pointer;
108 typedef const T* const_iterator;
109 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
111#if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
113 typedef T& reference;
115 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
117 typedef const_pointer pointer;
118 typedef const_reference reference;
119 typedef const_pointer iterator;
120 typedef const_reverse_iterator reverse_iterator;
127 : mbegin(ETL_NULLPTR),
136 template <
typename U,
size_t Size,
typename =
typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value,
void>::type>
139 , mend(a.data() + a.size())
146 template <
typename U,
size_t Size,
typename =
typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value,
void>::type>
149 , mend(a.data() + a.size())
156 template <
typename U,
size_t Size>
166 template <
typename U,
size_t Size>
174#if ETL_USING_STL && ETL_USING_CPP11
178 template <
typename U,
size_t Size,
typename =
typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value,
void>::type>
179 ETL_CONSTEXPR
array_view(std::array<U, Size>& a) ETL_NOEXCEPT
181 , mend(a.data() + a.size())
188 template <
typename U,
size_t Size,
typename =
typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value,
void>::type>
189 ETL_CONSTEXPR
array_view(
const std::array<U, Size>& a) ETL_NOEXCEPT
191 , mend(a.data() + a.size())
201 template <
typename TContainer,
typename =
typename etl::enable_if<!etl::is_po
inter<etl::remove_reference_t<TContainer>>::value &&
202 !etl::is_array<etl::remove_reference_t<TContainer>>::value &&
203 etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<
typename etl::remove_reference_t<TContainer>::value_type>>::value,
void>::type>
204 ETL_CONSTEXPR
array_view(TContainer&& a) ETL_NOEXCEPT
206 , mend(a.data() + a.size())
214 template <
typename TContainer>
227 template <
typename TContainer>
240 template <
typename TIterator>
241 ETL_CONSTEXPR
array_view(
const TIterator begin_,
const TIterator end_) ETL_NOEXCEPT
250 template <
typename TIterator,
252 ETL_CONSTEXPR
array_view(
const TIterator begin_,
const TSize size_) ETL_NOEXCEPT
261 template<
size_t Array_Size>
262 ETL_CONSTEXPR
array_view(T(&begin_)[Array_Size]) ETL_NOEXCEPT
264 mend(begin_ + Array_Size)
272 : mbegin(other.mbegin),
320 const_pointer
data() const ETL_NOEXCEPT
336 const_iterator
begin() const ETL_NOEXCEPT
344 const_iterator
cbegin() const ETL_NOEXCEPT
352 iterator
end() ETL_NOEXCEPT
360 const_iterator
end() const ETL_NOEXCEPT
376 reverse_iterator
rbegin() ETL_NOEXCEPT
378 return reverse_iterator(mend);
384 const_reverse_iterator
rbegin() const ETL_NOEXCEPT
386 return const_reverse_iterator(mend);
392 const_reverse_iterator
crbegin() const ETL_NOEXCEPT
394 return const_reverse_iterator(mend);
400 reverse_iterator
rend() ETL_NOEXCEPT
402 return reverse_iterator(mbegin);
408 const_reverse_iterator
rend() const ETL_NOEXCEPT
410 return const_reverse_iterator(mbegin);
416 const_reverse_iterator
crend() const ETL_NOEXCEPT
418 return const_reverse_iterator(mbegin);
424 ETL_CONSTEXPR
bool empty() const ETL_NOEXCEPT
426 return (mbegin == mend);
432 ETL_CONSTEXPR
size_t size() const ETL_NOEXCEPT
434 return static_cast<size_t>(mend - mbegin);
450 mbegin = other.mbegin;
458 template <
typename TIterator>
459 void assign(
const TIterator begin_,
const TIterator end_)
468 template <
typename TIterator,
470 void assign(
const TIterator begin_,
const TSize size_)
476#if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
489 const_reference
operator[](
const size_t i)
const ETL_NOEXCEPT
494#if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
509 const_reference
at(
const size_t i)
const
521 using ETL_OR_STD::swap;
523 swap(mbegin, other.mbegin);
524 swap(mend, other.mend);
562 return (lhs.
size() == rhs.
size()) &&
571 return !(lhs == rhs);
579 return etl::lexicographical_compare(lhs.
begin(), lhs.
end(), rhs.
begin(), rhs.
end());
616 template <
typename TArray>
617 array_view(TArray& a)
618 -> array_view<typename TArray::value_type>;
620 template <
typename TIterator>
621 array_view(
const TIterator begin_,
const TIterator end_)
622 -> array_view<etl::remove_pointer_t<TIterator>>;
624 template <
typename TIterator,
626 array_view(
const TIterator begin_,
const TSize size_)
627 -> array_view<etl::remove_pointer_t<TIterator>>;
633#if ETL_USING_8BIT_TYPES
634 template <
typename T>
635 struct hash<
etl::array_view<T> >
639 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(view.
data()),
640 reinterpret_cast<const uint8_t*
>(view.
data() + view.
size()));
void swap(etl::array_view< T > &lhs, etl::array_view< T > &rhs) ETL_NOEXCEPT
Swaps the values.
Definition array_view.h:650
Array view.
Definition array_view.h:101
ETL_CONSTEXPR array_view(etl::array< U, Size > &a, typename etl::enable_if< etl::is_same< typename etl::remove_cv< T >::type, typename etl::remove_cv< U >::type >::value, void >::type *=0) ETL_NOEXCEPT
Construct from etl::array.
Definition array_view.h:157
friend bool operator!=(const array_view< T > &lhs, const array_view< T > &rhs)
Inequality for array views.
Definition array_view.h:569
ETL_CONSTEXPR array_view(const array_view &other) ETL_NOEXCEPT
Copy constructor.
Definition array_view.h:271
ETL_CONSTEXPR array_view() ETL_NOEXCEPT
Default constructor.
Definition array_view.h:126
reference front()
Returns a reference to the first element.
Definition array_view.h:280
const_reference back() const
Returns a const reference to the last element.
Definition array_view.h:304
iterator end() ETL_NOEXCEPT
Returns an iterator to the end of the array.
Definition array_view.h:352
const_iterator begin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the array.
Definition array_view.h:336
ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the array.
Definition array_view.h:432
friend bool operator<=(const array_view< T > &lhs, const array_view< T > &rhs)
Less-than-equal for array views.
Definition array_view.h:593
ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
Returns the maximum possible size of the array.
Definition array_view.h:440
void swap(array_view &other) ETL_NOEXCEPT
Swaps with another array_view.
Definition array_view.h:519
const_iterator cbegin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the array.
Definition array_view.h:344
ETL_CONSTEXPR array_view(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 array_view.h:228
const_iterator end() const ETL_NOEXCEPT
Returns a const iterator to the end of the array.
Definition array_view.h:360
ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the array size is zero.
Definition array_view.h:424
const_reference front() const
Returns a const reference to the first element.
Definition array_view.h:288
ETL_CONSTEXPR array_view(const etl::array< U, Size > &a, typename etl::enable_if< etl::is_same< typename etl::remove_cv< T >::type, typename etl::remove_cv< U >::type >::value, void >::type *=0) ETL_NOEXCEPT
Construct from etl::array.
Definition array_view.h:167
const_reference at(const size_t i) const
Returns a const reference to the indexed value.
Definition array_view.h:509
iterator begin() ETL_NOEXCEPT
Returns an iterator to the beginning of the array.
Definition array_view.h:328
array_view & operator=(const array_view &other) ETL_NOEXCEPT
Assign from a view.
Definition array_view.h:448
void fill(const T &value)
Fills the array.
Definition array_view.h:552
friend bool operator>(const array_view< T > &lhs, const array_view< T > &rhs)
Greater-than for array views.
Definition array_view.h:585
friend bool operator==(const array_view< T > &lhs, const array_view< T > &rhs)
Equality for array views.
Definition array_view.h:560
ETL_CONSTEXPR array_view(const TIterator begin_, const TIterator end_) ETL_NOEXCEPT
Construct from iterators.
Definition array_view.h:241
const_reverse_iterator rend() const ETL_NOEXCEPT
Returns a const reverse iterator to the end of the array.
Definition array_view.h:408
void remove_prefix(const size_type n) ETL_NOEXCEPT
Shrinks the view by moving its start forward.
Definition array_view.h:530
pointer data() ETL_NOEXCEPT
Returns a pointer to the first element of the internal storage.
Definition array_view.h:312
friend bool operator>=(const array_view< T > &lhs, const array_view< T > &rhs)
Greater-than-equal for array views.
Definition array_view.h:601
void remove_suffix(const size_type n) ETL_NOEXCEPT
Shrinks the view by moving its end backward.
Definition array_view.h:541
ETL_CONSTEXPR array_view(const TIterator begin_, const TSize size_) ETL_NOEXCEPT
Construct from iterator and size.
Definition array_view.h:252
ETL_CONSTEXPR array_view(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 array_view.h:215
const_reference operator[](const size_t i) const ETL_NOEXCEPT
Returns a const reference to the indexed value.
Definition array_view.h:489
void assign(const TIterator begin_, const TIterator end_)
Assign from iterators.
Definition array_view.h:459
void assign(const TIterator begin_, const TSize size_)
Assign from iterator and size.
Definition array_view.h:470
const_reverse_iterator crend() const ETL_NOEXCEPT
Returns a const reverse iterator to the end of the array.
Definition array_view.h:416
friend bool operator<(const array_view< T > &lhs, const array_view< T > &rhs)
Less-than for array views.
Definition array_view.h:577
ETL_CONSTEXPR array_view(T(&begin_)[Array_Size]) ETL_NOEXCEPT
Construct from C array.
Definition array_view.h:262
reverse_iterator rend() ETL_NOEXCEPT
Returns a reverse iterator to the end of the array.
Definition array_view.h:400
const_reverse_iterator rbegin() const ETL_NOEXCEPT
Returns a const reverse iterator to the reverse beginning of the array.
Definition array_view.h:384
const_pointer data() const ETL_NOEXCEPT
Returns a const pointer to the first element of the internal storage.
Definition array_view.h:320
reference back()
Returns a reference to the last element.
Definition array_view.h:296
const_reverse_iterator crbegin() const ETL_NOEXCEPT
Returns a const reverse iterator to the reverse beginning of the array.
Definition array_view.h:392
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition exception.h:69
Definition array_view.h:73
Definition array_view.h:87
enable_if
Definition type_traits_generator.h:1254
is_array
Definition type_traits_generator.h:1154
is_pointer
Definition type_traits_generator.h:1164
is_same
Definition type_traits_generator.h:1104
remove_cv
Definition type_traits_generator.h:1031
remove_reference
Definition type_traits_generator.h:941
bitset_ext
Definition absolute.h:39
ETL_CONSTEXPR T * to_address(T *p) ETL_NOEXCEPT
Definition memory.h:62
ETL_CONSTEXPR TContainer::const_iterator cend(const TContainer &container)
Definition iterator.h:1012