Stack-allocated vector that mimics std::vector interface.
- standards:
c++17- c++20
- c++23
- compilers:
- icc-2024.1
- gcc-10
- gcc-11
- gcc-12
- gcc-13
- gcc-14
- clang-15 (partial, benchmark fails to compile)
- clang-16
- clang-17 (partial, benchmark fails to compile)
- clang-18
Static Vector provides two C++ template classes that offer functionality similar to std::vector but with fixed capacity:
- static_vector: A container that stores data in internal memory allocated on the stack.
- static_vector_adapter: A non-owning wrapper over existing C-arrays or
std::array.
Both classes attempt to mimic the std::vector API as closely as possible, with limitations related to their fixed-size nature.
- Fixed capacity containers
- Customizable bounds checking (Exception, Assertion, LimitToBound, or NoCheck)
- Memory-efficient
- Compatible with C++20 and above
- Comprehensive test suite using Google Test framework
- Benchmarks using Google Benchmark
- CMake 3.10 or higher
- C++20 compatible compiler (GCC, Clang, etc.)
- Google Test framework (for unit tests)
- Google Benchmark library (for performance testing)
- Doxygen (optional, for documentation generation)
cmake -S. -B build
cmake --build buildThe project consists of several components:
The main header file containing both static_vector and static_vector_adapter class template definitions.
A simple demonstration program showcasing basic usage of the vector classes.
Comprehensive unit tests using Google Test framework to verify functionality.
cmake -S. -B build
cmake --build build --target sv_unittest
ctest --test-dir buildPerformance benchmarks using Google Benchmark library.
The project offers two types of containers:
static_vector: A container that stores data in internal memory allocated on the stack.static_vector_adapter: A non-owning wrapper over existing C-arrays orstd::array.
Both classes attempt to mimic the std::vector API as closely as possible, with limitations related to their fixed-size nature.
Both classes support different bound checking strategies, controlled by the BoundCheckStrategy enum:
- Exception: Throws an exception if bounds are violated
- Throws
std::overflow_errorwhen vector is full - Throws
std::out_of_rangefor invalid iterator positions
- Throws
- Assert: Uses assertions to check bounds (debug mode only)
- LimitToBound: Silently limits the position to valid range without throwing
- NoCheck (UB): No checks are performed; bound violations lead to undefined behavior
API documentation can be generated using Doxygen. If Doxygen is found during configuration, it will generate HTML documentation in the build directory.
cmake -S. -B build -DBUILD_DOCS=ON
cmake --build build --target doc_doxygenThe generated documentation will be available in build/docs/html.
This project is licensed under the Creative Commons License.