This is header-only C++11 library that offers several new containers:
small_vector
small_flat_set
small_flat_map
small_flat_multiset
small_flat_multimap
small_unordered_flat_set
small_unordered_flat_map
small_unordered_flat_multiset
small_unordered_flat_multimap
compact_vector
segmented_vector
segmented_devector
All containers are defined in namespace sfl
.
sfl::small_vector
is a sequence container similar to std::vector
that internally holds statically allocated array of size N
and stores elements into this array until the number of elements is not greater than N
, which avoids dynamic memory allocation and deallocation. Size N
is is specified at the compile time as a template parameter.
Small flat maps and sets from namespace sfl
are associative containers similar to standard maps and sets, but with the storage model identical to the storage model of sfl::small_vector
, i.e. each of them internally holds statically allocated array of size N
and stores elements into this array until the number of elements is not greater than N
. Elements of these containers are always stored contiguously into the memory.
sfl::compact_vector
is a sequence container similar to std::vector
that always has capacity()
equal to size()
. Compact vector reallocates storage every time when element is inserted or removed in order to keep capacity and size equal. That means insertions and removals are very inefficient.
This container is inspired by OpenFOAM's container List
.
sfl::segmented_vector
is a sequence container similar to std::vector
that allows fast insertion at its end. The storage of segmented vector consists of a sequence of individually allocated arrays of size N
which are referred to as segments. Size N
is specified at the compile time as a template parameter.
sfl::segmented_devector
is a sequence container similar to std::deque
that allows fast insertion and deletion at both its beginning and its end. The storage of segmented double-ended vector consists of a sequence of individually allocated arrays of size N
which are referred to as segments. Size N
is specified at the compile time as a template parameter.
This library requires C++11 compiler or newer.
If available, the library uses the features of the newer C++ standards.
Tested compilers:
- GCC 4.8.5 on CentOS 7 (C++11)
- Clang 3.4.2 on CentOS 7 (C++11)
- GCC 13.2.1 on Arch Linux (C++11, 14, 17, 20, 23)
- Clang 16.0.6 on Arch Linux (C++11, 14, 17, 20)
- MSVC 19.38 (C++14, 17, 20, latest)
Copy subdirectory sfl
from directory include
into your project directory and #include
what you need.
This library can be integrated into CMake project using CMake module FetchContent.
Step 1: Add the following lines into your CMakeLists.txt
:
include(FetchContent)
FetchContent_Declare(
sfl
GIT_REPOSITORY https://github.com/slavenf/sfl-library)
FetchContent_MakeAvailable(sfl)
Step 2: Add this library as a dependency to your executable or library:
target_link_libraries(your_target_name PRIVATE sfl)
Step 3: #include
what you need.
This library by default throw exceptions in case of error.
If macro SFL_NO_EXCEPTIONS
is defined then library avoids using exceptions and calls std::abort
in case of error.
This library does not automatically detect whether the compiler is invoked with appropriate flag or not, like -fno-exceptions
in GCC and Clang.
This library extensively uses macro assert
from header <cassert>
.
The definition of the macro assert
depends on another macro, NDEBUG
, which is not defined by the standard library.
If macro NDEBUG
is defined then assert
does nothing.
If macro NDEBUG
is not defined then assert
performs check. If check fails, assert
outputs implementation-specific diagnostic information on the standard error output and calls std::abort
.
The detailed documentation is located in directory doc
. The detailed documentation is handwritten in Markdown format, it is not automatically generated with tools like Doxygen, so there may be some errors or mistakes. If you find one, please report it.
Test programs and scripts are located in directory test
.
Tested compilers are listed in section Requirements.
Each test program is checked with Valgrind tool.
Licensed under zlib license. The license text is in file LICENSE.txt
.