One of my favorite data structures in C++ is InlineVector<T,N>. If the number of elements is <= N then it all fits in the preallocated space.
This is great for keeping memory on the stack when N is small, yet allow heap memory overflow for larger N.
This is great for keeping memory on the stack when N is small, yet allow heap memory overflow for larger N.