This is header-only C++11 library that offers several new or less-known containers.
vector
— Vector equivalent tostd::vector
, but not specialized forbool
and with a few minor differences.devector
— Double-ended vector that allows faster insertion and deletion at the front compared tovector
.small_vector
— Vector that embeds small statically allocated storage internally to avoid dynamic memory allocation when the number of elements is small.static_vector
— Vector with a fixed maximum capacity defined at compile time, backed entirely by statically allocated storage. Dynamic memory is never used.compact_vector
— Vector whosecapacity()
is always equal to itssize()
. Inspired by OpenFOAM's containerList
.segmented_vector
— Vector with segmented storage that allows fast insertion and deletion at the back without memory reallocation.segmented_devector
— Double-ended vector with segmented storage that allows fast insertion and deletion at both the front and back without memory reallocation.
small_unordered_linear_map
small_unordered_linear_set
small_unordered_linear_multimap
small_unordered_linear_multiset
static_unordered_linear_map
static_unordered_linear_set
static_unordered_linear_multimap
static_unordered_linear_multiset
- Compiles with GCC 4.8.5 and Clang 3.4.2.
- Containers support stateful allocators and allocators with fancy pointers.
- Containers have available range constructor
container(sfl::from_range_t, Range&& r)
in C++11. - Containers have available range insertion member function
insert_range(Range&& r)
in C++11. - Maps and sets support heterogeneous insertion, erasure and lookup in C++11.
- Functions taking iterator range properly handle input iterators.
- There is no undefined behavior when constructing maps and sets from range containing duplicates.
- There is no undefined behavior when inserting range containing duplicates into maps and sets.
- Vectors are not specialized for
bool
. - Static containers can be used for bare-metal embedded software development.
This library requires C++11 compiler or newer. If available, library uses features of newer C++ standards.
Tested compilers:
- GCC 4.8.5 on CentOS 7 (C++11)
- Clang 3.4.2 on CentOS 7 (C++11)
- GCC 7.3.1 on CentOS 7 (C++11, 14, 17)
- Clang 5.0.1 on CentOS 7 (C++11, 14, 17)
- GCC 15.1.1 on Arch Linux (C++11, 14, 17, 20, 23)
- Clang 20.1.6 on Arch Linux (C++11, 14, 17, 20, 23)
- MSVC 19.38 (C++14, 17, 20, latest)
Step 1: Copy sfl
subdirectory from include
into your project directory.
Step 2: Configure your project or compiler to search for include files in the directory containing sfl
subdirectory.
Step 3: #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 into your CMakeLists.txt
::
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
.