ktprime / sfl-library

C++11 header-only library. Small vector. Small flat map/set/multimap/multiset (ordered and unordered). Compact vector. Segmented vector.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sfl library

This is header-only C++11 library that offers several new containers:

All containers are defined in namespace sfl.

About small vector

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.

About small flat maps and sets

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.

About compact vector

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.

About segmented vector

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.

About segmented double-ended vector

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.

Requirements

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)

Installation and usage

Method 1: Manual copy-paste

Copy subdirectory sfl from directory include into your project directory and #include what you need.

Method 2: CMake integration

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.

Exceptions

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.

Debugging

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.

Detailed documentation

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.

Tests

Test programs and scripts are located in directory test.

Tested compilers are listed in section Requirements.

Each test program is checked with Valgrind tool.

License

Licensed under zlib license. The license text is in file LICENSE.txt.

About

C++11 header-only library. Small vector. Small flat map/set/multimap/multiset (ordered and unordered). Compact vector. Segmented vector.

License:zlib License


Languages

Language:C++ 99.9%Language:Shell 0.1%Language:Makefile 0.0%Language:Batchfile 0.0%Language:CMake 0.0%