Custom std::array or std::vector implementation that contains a partial vector-like interface implementation. Internal implementation is changed at compile-time to either use the heap if THINGSBOARD_ENABLE_DYNAMIC is set or the stack otherwise.
More...
|
| | Container () |
| | Default constructor, simply initalizes the underlying c-style array with the necessary capacity. That capacity always has to be bigger than 0, because initalizing a 0 length c-style array can cause certain compilers to produce errors. More...
|
| |
| | 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 default constructed instances of the underlying type used. Simply forwards the arguments to the insert method, meaning if the initally allocated Capacity is not big enough to hold all elements, then this method will assert and stop the application. More...
|
| |
| template<typename InputIterator > |
| | Container (InputIterator const &first, InputIterator const &last) |
| | Copies all elements from the given start to exclusively the given end iterator into the underlying data container. Simply forwards the arguments to the insert method, meaning if the initally allocated Capacity is not big enough to hold all elements, then this method will assert and stop the application. More...
|
| |
| template<typename Iterable_Container > |
| | Container (Iterable_Container const &container) |
| | Accesses the begin and end iterator of the given data container and forwards the call to the iterator based constructor. More...
|
| |
| template<typename InputIterator > |
| void | assign (InputIterator const &first, InputIterator const &last) |
| | Copies all elements from the given start to exclusively the given end iterator into the underlying data container. Simply forwards the arguments to the insert method, meaning if the initally allocated Capacity is not big enough to hold all elements, then this method will assert and stop the application. More...
|
| |
| template<typename Container > |
| void | assign (Container const &container) |
| |
| bool | empty () const |
| | Returns whether there are any elements in the underlying data container. More...
|
| |
| size_type | size () const |
| | Gets the current amount of elements in the underlying data container. More...
|
| |
| size_type constexpr | capacity () const |
| | Gets the maximum amount of elements that can be stored in the underlying data container. More...
|
| |
| iterator | begin () |
| | Returns an iterator to the first element of the underlying data container. If the array is empty, the returned iterator will be equal to end() More...
|
| |
| const_iterator | begin () const |
| | Returns an iterator to the first element of the underlying data container. If the array is empty, the returned iterator will be equal to end() More...
|
| |
| const_iterator | cbegin () const |
| | Returns an iterator to the first element of the underlying data container. If the array is empty, the returned iterator will be equal to end() More...
|
| |
| reference | front () |
| | Returns a reference to the first element of the array. If the array is empty this method will assert and stop the application, because there is no valid element to return. More...
|
| |
| const_reference | front () const |
| | Returns a reference to the first element of the array. If the array is empty this method will assert and stop the application, because there is no valid element to return. More...
|
| |
| reference | back () |
| | Returns a reference to the last element of the array. If the array is empty this method will assert and stop the application, because there is no valid element to return. More...
|
| |
| const_reference | back () const |
| | Returns a reference to the last element of the array. If the array is empty this method will assert and stop the application, because there is no valid element to return. More...
|
| |
| iterator | end () |
| | Returns a iterator to one-past-the-last element of the underlying data container. More...
|
| |
| const_iterator | end () const |
| | Returns a iterator to one-past-the-last element of the underlying data container. More...
|
| |
| const_iterator | cend () const |
| | Returns a iterator to one-past-the-last element of the underlying data container. More...
|
| |
| void | push_back (const_reference element) |
| | Appends the given element at the end of the underlying data container. More...
|
| |
| template<typename InputIterator > |
| 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 data container. The copying is started from the position before the given iterator (position - 1) More...
|
| |
| void | erase (const_iterator position) |
| | Removes the element at the given position, has to move all element one to the left if the iterator does not point to the last valid element in the underlying data container. More...
|
| |
| reference | at (size_type const &index) |
| | Returns a reference to the element at specified location index, with bounds checking. More...
|
| |
| const_reference | at (size_type const &index) const |
| | Returns a reference to the element at specified location index, with bounds checking. More...
|
| |
| reference | operator[] (size_type index) |
| | Returns a reference to the element at specified location index. No bounds checking is performed. More...
|
| |
| const_reference | operator[] (size_type index) const |
| | Returns a reference to the element at specified location index. No bounds checking is performed. More...
|
| |
| void | clear () |
| | Erases all elements from the container. After this call, size() returns zero. More...
|
| |
template<typename T,
size_t Capacity>
class Container< T, Capacity >
Custom std::array or std::vector implementation that contains a partial vector-like interface implementation. Internal implementation is changed at compile-time to either use the heap if THINGSBOARD_ENABLE_DYNAMIC is set or the stack otherwise.
- Note
- Allows to use the exact same method calls independent on if the custom Container implementation or std::vector is used. Support for the vector-like interface is achieved through a simple index that keeps count of the elements that have been instantiated with actual values by the push or insert method. Iterator based support is achieved through returning a pointer, which can be automatically used the same as an iterator implementation tagged as std::random_iterator_tag. This allows to use the most efficient implementation of standard algorithms, while keeping the actual internal implementation as simple as possible.
The elements are stored contiguously, which means that elements can be accessed not only through iterators, but also using offsets to regular pointers to elements. This means that a pointer to an element of a container may be passed to any function that expects a pointer to an element of a c-array
- Template Parameters
-
| T | The type of the elements in the underlying data container. Must be both CopyAssignable (have a copy assignment operator, for the push_back operation) as well as be Default-Constructible (have a default constructor, for the construction of the intial state of the underlying data container) |
| Capacity | Amount of elements that can ever be saved into the underlying data container, allows to wrap a simple c-array and allocate it on the stack. Attempting to allocate more elements is not possible, because the size is fixed at compile-time |