I'm working on an embedded application in which I'd love to use a container like std::vector<>
. Unfortunately I must not use the heap. So std::vector<>
could not be used. So I'm looking for an alternative.
I've seen boost static_vector
but the boost approach seems too heavy for the microcontroller as far as I've seen. Or are there any experiences using boost on a small microcontroller (for example only the static_vector?)
One assumption could be made: the maximum number of entries during the whole application runtime is known at compile time.
So I'm wondering if there is any open source solution for this or if I have to implement a container by myself which is based on the std::array<>
implementation and adds some logic to enable the following operations:
Add (push_back()
) and remove (erase()
) elements during the runtime. Providing the typical container iterators and a random access. Also the short hand for ( : )
loop should be available.
So my naive approach would be:
Providing the iterators, and the random access seems easy to me, and should be mostly based on the
std::array<>
functionsAdding the add (
push_back
) and remove (erase
) should be no problem with some logic.But how is the
for ( : )
loop support to implement?Are there any other things I need to consider?