22#if THINGSBOARD_ENABLE_DYNAMIC
27template <
typename T,
size_t Capacity>
40#if THINGSBOARD_ENABLE_DYNAMIC
55 , m_capacity{other.m_capacity}
57 m_elements =
new T[m_capacity]{};
68 m_elements =
new T[other.m_capacity]{};
69 m_capacity = other.m_capacity;
82 static_assert(Capacity > 0);
94 for (; count > 0; --count) {
107 template<
typename InputIterator>
108 Container(InputIterator
const & first, InputIterator
const & last)
120 template<
typename Iterable_Container>
128 template<
typename InputIterator>
129 void assign(InputIterator
const & first, InputIterator
const & last) {
134 template<
typename Container>
153#if THINGSBOARD_ENABLE_DYNAMIC
183 assert(m_size != 0U);
184 return m_elements[0U];
189 assert(m_size != 0U);
190 return m_elements[0U];
197 assert(m_size != 0U);
198 return m_elements[m_size - 1U];
203 assert(m_size != 0U);
204 return m_elements[m_size - 1U];
210 return m_elements + m_size;
215 return m_elements + m_size;
231#if THINGSBOARD_ENABLE_DYNAMIC
234 assert(m_size < Capacity);
236 if (is_destructible()) {
237 m_elements[m_size].~T();
239 m_elements[m_size] = element;
256 template<
typename InputIterator>
257 void insert(
iterator position, InputIterator
const & first, InputIterator
const & last) {
259 assert_iterator_in_range(position);
260#if !THINGSBOARD_ENABLE_DYNAMIC
263 for (
auto it = first; it != last; ++it, ++position) {
264#if THINGSBOARD_ENABLE_DYNAMIC
267 if (is_destructible()) {
285 assert_iterator_in_range(position);
288 for (
size_type i = index; i <= m_size; ++i) {
289 if (is_destructible()) {
291 m_elements[i] = m_elements[i + 1];
294 if (is_destructible()) {
295 m_elements[m_size].~T();
305 assert(index < m_size);
306 return m_elements[index];
311 assert(index < m_size);
312 return m_elements[index];
319 return m_elements[index];
324 return m_elements[index];
338 bool is_destructible()
const {
339#if THINGSBOARD_ENABLE_STL
340 return std::is_destructible<T>::value;
343 return ArduinoJson::ARDUINOJSON_VERSION_NAMESPACE::detail::is_class<T>::value;
348 assert(
cbegin() >= position);
349 assert(position <
cend());
352#if THINGSBOARD_ENABLE_DYNAMIC
354 void increase_capacity() {
355 if (m_size == m_capacity) {
356 m_capacity = (m_capacity == 0) ? 1 : 2 * m_capacity;
357 T* new_elements =
new T[m_capacity]();
358 if (m_elements !=
nullptr) {
359 memcpy(new_elements, m_elements, m_size *
sizeof(T));
362 m_elements = new_elements;
367#if THINGSBOARD_ENABLE_DYNAMIC
369 size_t m_capacity = {};
Custom std::array or std::vector implementation that contains a partial vector-like interface impleme...
Definition: Container.h:29
T value_type
Definition: Container.h:31
size_type size() const
Gets the current amount of elements in the underlying data container.
Definition: Container.h:147
reference back()
Returns a reference to the last element of the array. If the array is empty this method will assert a...
Definition: Container.h:196
iterator begin()
Returns an iterator to the first element of the underlying data container. If the array is empty,...
Definition: Container.h:165
reference front()
Returns a reference to the first element of the array. If the array is empty this method will assert ...
Definition: Container.h:182
reference at(size_type const &index)
Returns a reference to the element at specified location index, with bounds checking.
Definition: Container.h:304
Container(Iterable_Container const &container)
Accesses the begin and end iterator of the given data container and forwards the call to the iterator...
Definition: Container.h:121
void erase(const_iterator position)
Removes the element at the given position, has to move all element one to the left if the iterator do...
Definition: Container.h:284
Container()
Default constructor, simply initalizes the underlying c-style array with the necessary capacity....
Definition: Container.h:78
void insert(iterator position, InputIterator const &first, InputIterator const &last)
Copies all elements from the given start to exclusively the given end iterator into the underlying da...
Definition: Container.h:257
const_iterator cbegin() const
Returns an iterator to the first element of the underlying data container. If the array is empty,...
Definition: Container.h:175
size_type constexpr capacity() const
Gets the maximum amount of elements that can be stored in the underlying data container.
Definition: Container.h:157
void push_back(const_reference element)
Appends the given element at the end of the underlying data container.
Definition: Container.h:230
const_reference at(size_type const &index) const
Returns a reference to the element at specified location index, with bounds checking.
Definition: Container.h:310
const_pointer const_iterator
Definition: Container.h:38
const_iterator begin() const
Returns an iterator to the first element of the underlying data container. If the array is empty,...
Definition: Container.h:170
bool empty() const
Returns whether there are any elements in the underlying data container.
Definition: Container.h:141
const_iterator cend() const
Returns a iterator to one-past-the-last element of the underlying data container.
Definition: Container.h:219
T & reference
Definition: Container.h:33
reference operator[](size_type index)
Returns a reference to the element at specified location index. No bounds checking is performed.
Definition: Container.h:318
T const & const_reference
Definition: Container.h:34
void clear()
Erases all elements from the container. After this call, size() returns zero.
Definition: Container.h:330
pointer iterator
Definition: Container.h:37
void assign(InputIterator const &first, InputIterator const &last)
Copies all elements from the given start to exclusively the given end iterator into the underlying da...
Definition: Container.h:129
iterator end()
Returns a iterator to one-past-the-last element of the underlying data container.
Definition: Container.h:209
const_reference front() const
Returns a reference to the first element of the array. If the array is empty this method will assert ...
Definition: Container.h:188
const_reference back() const
Returns a reference to the last element of the array. If the array is empty this method will assert a...
Definition: Container.h:202
size_t size_type
Definition: Container.h:32
const_reference operator[](size_type index) const
Returns a reference to the element at specified location index. No bounds checking is performed.
Definition: Container.h:323
const_iterator end() const
Returns a iterator to one-past-the-last element of the underlying data container.
Definition: Container.h:214
Container(InputIterator const &first, InputIterator const &last)
Copies all elements from the given start to exclusively the given end iterator into the underlying da...
Definition: Container.h:108
Container(size_type count, const_reference value=T{})
Creates the constructor with the given amount of elements, either x copies of the passed value or x d...
Definition: Container.h:91
T * pointer
Definition: Container.h:35
void assign(Container const &container)
Definition: Container.h:135
T const * const_pointer
Definition: Container.h:36
static size_t distance(InputIterator const &first, InputIterator const &last)
Calculates the distance between two iterators.
Definition: Helper.h:85