31#ifndef ETL_ARRAY_INCLUDED
32#define ETL_ARRAY_INCLUDED
41#include "static_assert.h"
62 array_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
63 :
exception(reason_, file_name_, line_number_)
72 class array_out_of_range :
public array_exception
76 array_out_of_range(string_type file_name_, numeric_type line_number_)
77 : array_exception(
"array:range", file_name_, line_number_)
86 template <
typename T,
size_t SIZE_>
95 static ETL_CONSTANT
size_t SIZE = SIZE_;
98 typedef size_t size_type;
99 typedef ptrdiff_t difference_type;
100 typedef T& reference;
101 typedef const T& const_reference;
103 typedef const T* const_pointer;
105 typedef const T* const_iterator;
106 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
107 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
119 reference
at(
size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
132 const_reference
at(
size_t i)
const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
146 reference
operator[](
size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
159 ETL_CONSTEXPR const_reference
operator[](
size_t i)
const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
162#if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_INDEX_OPERATOR
178 ETL_STATIC_ASSERT(SIZE > 0,
"Array is empty.");
187 ETL_CONSTEXPR const_reference
front() const ETL_NOEXCEPT
189 ETL_STATIC_ASSERT(SIZE > 0,
"Array is empty.");
201 ETL_STATIC_ASSERT(SIZE > 0,
"Array is empty.");
210 ETL_CONSTEXPR const_reference
back() const ETL_NOEXCEPT
212 ETL_STATIC_ASSERT(SIZE > 0,
"Array is empty.");
231 ETL_CONSTEXPR const_pointer
data() const ETL_NOEXCEPT
254 ETL_CONSTEXPR const_iterator
begin() const ETL_NOEXCEPT
263 ETL_CONSTEXPR const_iterator
cbegin() const ETL_NOEXCEPT
273 iterator
end() ETL_NOEXCEPT
282 ETL_CONSTEXPR const_iterator
end() const ETL_NOEXCEPT
301 reverse_iterator
rbegin() ETL_NOEXCEPT
303 return reverse_iterator(
end());
310 ETL_CONSTEXPR const_reverse_iterator
rbegin() const ETL_NOEXCEPT
312 return const_reverse_iterator(
end());
319 ETL_CONSTEXPR const_reverse_iterator
crbegin() const ETL_NOEXCEPT
321 return const_reverse_iterator(
end());
329 reverse_iterator
rend() ETL_NOEXCEPT
331 return reverse_iterator(
begin());
338 ETL_CONSTEXPR const_reverse_iterator
rend() const ETL_NOEXCEPT
340 return const_reverse_iterator(
begin());
347 ETL_CONSTEXPR const_reverse_iterator
crend() const ETL_NOEXCEPT
349 return const_reverse_iterator(
begin());
360 ETL_CONSTEXPR
bool empty() const ETL_NOEXCEPT
369 ETL_CONSTEXPR
size_t size() const ETL_NOEXCEPT
391 ETL_CONSTEXPR14
void fill(parameter_t value)
400 ETL_CONSTEXPR14
void swap(
array& other) ETL_NOEXCEPT_FROM(ETL_OR_STD::swap(etl::declval<T&>(), etl::declval<T&>()))
402 using ETL_OR_STD::swap;
404 for (
size_t i = 0UL; i < SIZE; ++i)
417 template <
typename TIterator>
418 iterator
assign(TIterator first,
const TIterator last)
430 template <
typename TIterator>
431 iterator
assign(TIterator first,
const TIterator last, parameter_t value)
437 etl::fill(p,
end(), value);
447 inline iterator
insert_at(
size_t position, parameter_t value)
459 iterator
insert(const_iterator position, parameter_t value)
463 iterator p = to_iterator(position);
465 etl::move_backward(p,
end() - 1,
end());
477 template <
typename TIterator>
478 inline iterator
insert_at(
size_t position, TIterator first,
const TIterator last)
491 template <
typename TIterator>
492 iterator
insert(const_iterator position, TIterator first,
const TIterator last)
496 iterator p = to_iterator(position);
499 size_t source_size = etl::distance(first, last);
500 size_t destination_space = etl::distance(position, cend());
503 if (source_size < destination_space)
505 size_t length = SIZE - (etl::distance(
begin(), p) + source_size);
506 etl::move_backward(p, p + length,
end());
532 iterator
erase(const_iterator position)
536 iterator p = to_iterator(position);
537 etl::move(p + 1,
end(), p);
561 iterator
erase(const_iterator first, const_iterator last)
565 iterator p = to_iterator(first);
566 etl::move(last, cend(), p);
575 inline iterator
erase_at(
size_t position, parameter_t value)
587 iterator
erase(const_iterator position, parameter_t value)
591 iterator p = to_iterator(position);
593 etl::move(p + 1,
end(), p);
605 iterator
erase_range(
size_t first,
size_t last, parameter_t value)
618 iterator
erase(const_iterator first, const_iterator last, parameter_t value)
622 iterator p = to_iterator(first);
624 p = etl::move(last, cend(), p);
625 etl::fill(p,
end(), value);
627 return to_iterator(first);
638 iterator to_iterator(const_iterator itr)
const
640 return const_cast<iterator
>(itr);
644 template <
typename T,
size_t SIZE_>
645 ETL_CONSTANT
size_t array<T, SIZE_>::SIZE;
652 template <
typename T>
661 static ETL_CONSTANT
size_t SIZE = 0;
663 typedef T value_type;
664 typedef size_t size_type;
665 typedef ptrdiff_t difference_type;
666 typedef T& reference;
667 typedef const T& const_reference;
669 typedef const T* const_pointer;
671 typedef const T* const_iterator;
672 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
673 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
685 reference
at(
size_t) ETL_NOEXCEPT
696 const_reference
at(
size_t)
const ETL_NOEXCEPT
719 ETL_CONSTEXPR const_reference
operator[](
size_t)
const ETL_NOEXCEPT
738 ETL_CONSTEXPR const_reference
front() const ETL_NOEXCEPT
757 ETL_CONSTEXPR const_reference
back()
const
776 ETL_CONSTEXPR const_pointer
data() const ETL_NOEXCEPT
799 ETL_CONSTEXPR const_iterator
begin() const ETL_NOEXCEPT
801 return const_iterator();
808 ETL_CONSTEXPR const_iterator
cbegin() const ETL_NOEXCEPT
810 return const_iterator();
818 iterator
end() ETL_NOEXCEPT
827 ETL_CONSTEXPR const_iterator
end() const ETL_NOEXCEPT
829 return const_iterator();
846 reverse_iterator
rbegin() ETL_NOEXCEPT
848 return reverse_iterator(
end());
855 ETL_CONSTEXPR const_reverse_iterator
rbegin() const ETL_NOEXCEPT
857 return const_reverse_iterator(
end());
864 ETL_CONSTEXPR const_reverse_iterator
crbegin() const ETL_NOEXCEPT
866 return const_reverse_iterator(
end());
874 reverse_iterator
rend() ETL_NOEXCEPT
876 return reverse_iterator(
begin());
883 ETL_CONSTEXPR const_reverse_iterator
rend() const ETL_NOEXCEPT
885 return const_reverse_iterator(
begin());
892 ETL_CONSTEXPR const_reverse_iterator
crend() const ETL_NOEXCEPT
894 return const_reverse_iterator(
begin());
905 ETL_CONSTEXPR
bool empty() const ETL_NOEXCEPT
914 ETL_CONSTEXPR
size_t size() const ETL_NOEXCEPT
936 ETL_CONSTEXPR14
void fill(parameter_t) ETL_NOEXCEPT
955 template <
typename TIterator>
956 iterator
assign(TIterator,
const TIterator) ETL_NOEXCEPT
968 template <
typename TIterator>
969 iterator
assign(TIterator,
const TIterator, parameter_t) ETL_NOEXCEPT
979 inline iterator
insert_at(
size_t, parameter_t) ETL_NOEXCEPT
989 iterator
insert(const_iterator, parameter_t) ETL_NOEXCEPT
1000 template <
typename TIterator>
1001 inline iterator
insert_at(
size_t, TIterator,
const TIterator) ETL_NOEXCEPT
1012 template <
typename TIterator>
1013 iterator
insert(const_iterator, TIterator,
const TIterator) ETL_NOEXCEPT
1033 iterator
erase(const_iterator) ETL_NOEXCEPT
1055 iterator
erase(const_iterator, const_iterator) ETL_NOEXCEPT
1065 inline iterator
erase_at(
size_t, parameter_t) ETL_NOEXCEPT
1075 iterator
erase(const_iterator, parameter_t) ETL_NOEXCEPT
1096 iterator
erase(const_iterator, const_iterator, parameter_t) ETL_NOEXCEPT
1106 template <
typename... T>
1107 array(T...) -> array<
typename etl::common_type<T...>::type,
sizeof...(T)>;
1113#if ETL_HAS_INITIALIZER_LIST
1114 template <
typename T,
typename... TValues>
1115 constexpr auto make_array(TValues&&... values) ETL_NOEXCEPT ->
etl::array<T,
sizeof...(TValues)>
1117 return { etl::forward<T>(values)... };
1126 template <
typename T, const
size_t SIZE>
1138 template <
typename T,
size_t SIZE>
1141 return etl::equal(lhs.
cbegin(), lhs.cend(), rhs.
cbegin());
1150 template <
typename T,
size_t SIZE>
1153 return !(lhs == rhs);
1162 template <
typename T,
size_t SIZE>
1165 return etl::lexicographical_compare(lhs.
cbegin(),
1177 template <
typename T,
size_t SIZE>
1180 return !(lhs > rhs);
1188 template <
typename T,
size_t SIZE>
1201 template <
typename T,
size_t SIZE>
1204 return !(lhs < rhs);
1215 template <
size_t Index,
typename T,
size_t Size>
1218 ETL_STATIC_ASSERT(Index < Size,
"Index out of bounds");
1230 template <
size_t Index,
typename T,
size_t Size>
1233 ETL_STATIC_ASSERT(Index < Size,
"Index out of bounds");
ETL_CONSTEXPR14 etl::enable_if< etl::is_random_iterator< TInputIterator >::value &&etl::is_random_iterator< TOutputIterator >::value, TOutputIterator >::type copy_s(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TOutputIterator o_end)
Definition algorithm.h:2368
ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t) ETL_NOEXCEPT
Definition array.h:685
ETL_NODISCARD ETL_CONSTEXPR14 reference operator[](size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS||ETL_NOT_CHECKING_INDEX_OPERATOR)
Definition array.h:146
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
Returns a const reverse iterator to the end of the array.
Definition array.h:883
ETL_NODISCARD ETL_CONSTEXPR14 reference operator[](size_t) ETL_NOEXCEPT
Definition array.h:708
iterator erase(const_iterator first, const_iterator last)
Definition array.h:561
ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator rend() ETL_NOEXCEPT
Returns a reverse iterator to the end of the array.
Definition array.h:329
iterator erase_at(size_t) ETL_NOEXCEPT
Definition array.h:1023
ETL_NODISCARD ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
Returns a const reference to the first element.
Definition array.h:738
ETL_NODISCARD ETL_CONSTEXPR const_reference operator[](size_t) const ETL_NOEXCEPT
Definition array.h:719
iterator assign(TIterator, const TIterator) ETL_NOEXCEPT
Definition array.h:956
ETL_NODISCARD ETL_CONSTEXPR14 reference front() ETL_NOEXCEPT
Returns a reference to the first element.
Definition array.h:176
ETL_NODISCARD ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
Returns a const pointer to the first element of the internal buffer.
Definition array.h:776
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
Returns a const reverse iterator to the reverse beginning of the array.
Definition array.h:319
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
Returns a const reverse iterator to the reverse beginning of the array.
Definition array.h:310
ETL_NODISCARD ETL_CONSTEXPR14 iterator end() ETL_NOEXCEPT
Returns an iterator to the end of the array.
Definition array.h:818
ETL_NODISCARD ETL_CONSTEXPR14 iterator begin() ETL_NOEXCEPT
Returns an iterator to the beginning of the array.
Definition array.h:245
delegate_type _buffer[SIZE]
Definition array.h:631
ETL_NODISCARD ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the array.
Definition array.h:254
iterator insert_at(size_t, parameter_t) ETL_NOEXCEPT
Definition array.h:979
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
Returns a const reverse iterator to the end of the array.
Definition array.h:892
iterator erase_range(size_t, size_t) ETL_NOEXCEPT
Definition array.h:1044
ETL_NODISCARD ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS||ETL_NOT_CHECKING_INDEX_OPERATOR)
Definition array.h:159
ETL_NODISCARD ETL_CONSTEXPR14 pointer data() ETL_NOEXCEPT
Returns a pointer to the first element of the internal buffer.
Definition array.h:222
iterator erase_range(size_t, size_t, parameter_t) ETL_NOEXCEPT
Definition array.h:1086
iterator erase_range(size_t first, size_t last)
Definition array.h:548
ETL_CONSTEXPR14 void fill(parameter_t) ETL_NOEXCEPT
Definition array.h:936
ETL_NODISCARD ETL_CONSTEXPR const_reference back() const ETL_NOEXCEPT
Returns a const reference to the last element.
Definition array.h:210
ETL_NODISCARD ETL_CONSTEXPR14 reference back() ETL_NOEXCEPT
Returns a reference to the last element.
Definition array.h:199
ETL_NODISCARD ETL_CONSTEXPR14 iterator begin() ETL_NOEXCEPT
Returns an iterator to the beginning of the array.
Definition array.h:790
ETL_CONSTEXPR14 void fill(parameter_t value)
Definition array.h:391
iterator insert_at(size_t, TIterator, const TIterator) ETL_NOEXCEPT
Definition array.h:1001
iterator erase(const_iterator) ETL_NOEXCEPT
Definition array.h:1033
iterator insert_at(size_t position, parameter_t value)
Definition array.h:447
iterator assign(TIterator, const TIterator, parameter_t) ETL_NOEXCEPT
Definition array.h:969
iterator erase_range(size_t first, size_t last, parameter_t value)
Definition array.h:605
ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Definition array.h:132
ETL_NODISCARD ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
Returns a const iterator to the end of the array.
Definition array.h:282
iterator insert(const_iterator, parameter_t) ETL_NOEXCEPT
Definition array.h:989
ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
Returns the maximum possible size of the array.
Definition array.h:923
ETL_NODISCARD ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
Returns a const iterator to the end of the array.
Definition array.h:827
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the array.
Definition array.h:914
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
Returns a const reverse iterator to the reverse beginning of the array.
Definition array.h:864
ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t) const ETL_NOEXCEPT
Definition array.h:696
ETL_CONSTEXPR14 void swap(array &) ETL_NOEXCEPT
Definition array.h:944
iterator erase_at(size_t position)
Definition array.h:520
ETL_NODISCARD ETL_CONSTEXPR const_reference back() const
Returns a const reference to the last element.
Definition array.h:757
iterator erase(const_iterator first, const_iterator last, parameter_t value)
Definition array.h:618
iterator erase(const_iterator position, parameter_t value)
Definition array.h:587
iterator insert(const_iterator, TIterator, const TIterator) ETL_NOEXCEPT
Definition array.h:1013
iterator erase(const_iterator, parameter_t) ETL_NOEXCEPT
Definition array.h:1075
ETL_NODISCARD ETL_CONSTEXPR14 pointer data() ETL_NOEXCEPT
Returns a pointer to the first element of the internal buffer.
Definition array.h:767
ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the array.
Definition array.h:808
iterator erase(const_iterator, const_iterator) ETL_NOEXCEPT
Definition array.h:1055
ETL_NODISCARD ETL_CONSTEXPR14 iterator end() ETL_NOEXCEPT
Returns an iterator to the end of the array.
Definition array.h:273
iterator insert(const_iterator position, parameter_t value)
Definition array.h:459
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
Returns a const reverse iterator to the end of the array.
Definition array.h:347
ETL_NODISCARD ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the array.
Definition array.h:799
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the array size is zero.
Definition array.h:360
iterator erase_at(size_t, parameter_t) ETL_NOEXCEPT
Definition array.h:1065
ETL_NODISCARD ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
Returns a const pointer to the first element of the internal buffer.
Definition array.h:231
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the array.
Definition array.h:369
ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Definition array.h:119
ETL_CONSTEXPR14 void swap(array &other) ETL_NOEXCEPT_FROM(ETL_OR_STD
Definition array.h:400
iterator insert(const_iterator position, TIterator first, const TIterator last)
Definition array.h:492
iterator assign(TIterator first, const TIterator last)
Definition array.h:418
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
Returns a const reverse iterator to the reverse beginning of the array.
Definition array.h:855
ETL_NODISCARD ETL_CONSTEXPR14 reference front() ETL_NOEXCEPT
Returns a reference to the first element.
Definition array.h:729
ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the array.
Definition array.h:263
iterator erase(const_iterator position)
Definition array.h:532
ETL_NODISCARD ETL_CONSTEXPR14 reference back() ETL_NOEXCEPT
Returns a reference to the last element.
Definition array.h:748
iterator assign(TIterator first, const TIterator last, parameter_t value)
Definition array.h:431
iterator erase(const_iterator, const_iterator, parameter_t) ETL_NOEXCEPT
Definition array.h:1096
ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator rend() ETL_NOEXCEPT
Returns a reverse iterator to the end of the array.
Definition array.h:874
iterator erase_at(size_t position, parameter_t value)
Definition array.h:575
ETL_NODISCARD ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
Returns a const reference to the first element.
Definition array.h:187
iterator insert_at(size_t position, TIterator first, const TIterator last)
Definition array.h:478
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
Returns a const reverse iterator to the end of the array.
Definition array.h:338
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the array size is zero.
Definition array.h:905
ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
Returns the maximum possible size of the array.
Definition array.h:378
#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
bitset_ext
Definition absolute.h:39
ETL_CONSTEXPR14 void swap(etl::typed_storage_ext< T > &lhs, etl::typed_storage_ext< T > &rhs) ETL_NOEXCEPT
Swap two etl::typed_storage_ext.
Definition alignment.h:838
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1190
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1202
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1151
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1139
T & get(array< T, Size > &a)
Definition array.h:1216
ETL_CONSTEXPR TContainer::const_iterator cend(const TContainer &container)
Definition iterator.h:1012
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1163
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1178
etl::conditional< etl::is_fundamental< T >::value||etl::is_pointer< T >::value, T, constT & >::type type
By default fundamental and pointer types are passed by value.
Definition parameter_type.h:48