For the past two decades, C++ programmers were using std::vector
as a default sequence container. It is a fast container that does not do a lot of allocations, stores elements in a CPU cache friendly way and because container stores the elements contiguously std::vector::data()
like functions allows to inter-operate with pure C functions.
But, we want more! There are cases when we do know the typical elements count to store in the vector, and we need to improve the performance of the vector by totally eliminating the memory allocations for that case.
Imagine that we are writing a high performance system for processing bank transactions. Transaction is a sequence of operations that must all succeed or fail if at least one of the operations failed. We know that the 99% of transactions consist of 8 or less operations and wish to speed up things:
#include <vector> class operation; template <class T> void execute_operations(const T&...