A simple, fixed-capacity vector backed by std::array for embedded and performance-critical use.
More...
#include <VectorFromArray.h>
|
|
bool | push_back (const T &value) |
| |
|
void | clear () |
| |
|
std::size_t | size () const |
| |
|
constexpr std::size_t | capacity () const |
| |
|
T & | operator[] (std::size_t idx) |
| |
|
const T & | operator[] (std::size_t idx) const |
| |
|
T * | begin () |
| |
|
T * | end () |
| |
|
const T * | begin () const |
| |
|
const T * | end () const |
| |
|
|
std::array< T, N > | data |
| |
|
std::size_t | sz |
| |
template<typename T, std::size_t N>
class tinyrobotics::VectorFromArray< T, N >
A simple, fixed-capacity vector backed by std::array for embedded and performance-critical use.
VectorFromArray provides a subset of the std::vector API, but with no dynamic memory allocation. All storage is allocated at compile time, making it suitable for microcontrollers, real-time systems, or any environment where heap usage is undesirable or unavailable.
Features:
- push_back() to add elements up to the fixed capacity N
- operator[] for element access (no bounds checking)
- size() and capacity() for querying current and maximum size
- clear() to reset the vector to empty
- begin()/end() iterators for range-based for loops
Limitations:
- Capacity is fixed at compile time (template parameter N)
- Exceeding capacity throws std::out_of_range (can be changed for embedded use)
- No erase, insert, or dynamic resizing
Example usage:
v.push_back(1);
v.push_back(2);
for (auto x : v) {
Serial.println(x);
}
v.clear();
A simple, fixed-capacity vector backed by std::array for embedded and performance-critical use.
Definition: VectorFromArray.h:47
- Template Parameters
-
| T | Element type |
| N | Maximum number of elements (capacity) |
The documentation for this class was generated from the following file: