GitHub - teslamotors/fixed-containers: C++ Fixed Containers (original) (raw)

C++ Fixed Containers

License Standard Ubuntu Ubuntu (clang) Windows CodeQL

Header-only C++20 library that provides containers with the following properties:

Features

Rich enum features

static_assert(fixed_containers::rich_enums::is_rich_enum); // Type-trait concept inline constexpr Color COLOR = Color::RED(); // Note the parens static_assert("RED" == COLOR.to_string()); // auto-provided member static_assert(COLOR.is_primary()); // Custom member static_assert(COLOR == Color::value_of("RED").value()); // auto-provided static_assert(4 == Color::count()); // auto-provided

More examples can be found here.

Examples

Integration

cmake

find_package(fixed_containers CONFIG REQUIRED)
target_link_libraries(<your_binary> fixed_containers::fixed_containers)

bazel

If you are managing dependencies with the newer bzlmod system, use the following in your MODULE.bazel file:

bazel_dep(name = "fixed_containers")
archive_override(
    module_name = "fixed_containers",
    strip_prefix = "fixed-containers-<commit>",
    urls = ["https://github.com/teslamotors/fixed-containers/archive/<commit>.tar.gz"],
)

If you are managing dependencies with the older WORKSPACE system, use the following in your WORKSPACE file:

http_archive(
    name = "fixed_containers",
    urls = ["https://github.com/teslamotors/fixed-containers/archive/<commit>.tar.gz"],
    strip_prefix = "fixed-containers-<commit>",
)

load("@fixed_containers//:fixed_containers_deps.bzl", "fixed_containers_deps")
fixed_containers_deps()

Then use in your targets like this:

cc_test(
    name = "test",
    srcs = ["test.cpp"],
    deps = [
        "@fixed_containers//:fixed_vector",
        "@fixed_containers//:enum_map",
        "@fixed_containers//:enum_set",
    ],
    copts = ["-std=c++20"],
)

Alternative

Since this is a header-only library, you can also:

Running the tests

cmake

  1. Build with the vcpkg toolchain file
mkdir build && cd build
cmake .. -DCMAKE_C_COMPILER=/bin/clang-13 -DCMAKE_CXX_COMPILER=/bin/clang++-13 -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build .
  1. Run tests

bazel

clang

  1. Build separately (optional)
CC=clang++-13 bazel build --config=clang ...
  1. Run tests
CC=clang++-13 bazel test --config=clang :all_tests

clang with libc++

CC=clang++-13 bazel build --config=clang_with_libcxx ...
  1. Run tests
CC=clang++-13 bazel test --config=clang_with_libcxx :all_tests

gcc

  1. Build separately (optional)
CC=g++-11 bazel build --config=gcc ...
  1. Run tests
CC=g++-11 bazel test --config=gcc :all_tests

clang-tidy

Run with:

run-clang-tidy -p . -extra-arg-before="-DFIXED_CONTAINERS_CLANG_TIDY_RUNNING"

The macro is needed to avoid analysis on some particularly slow places.

Tested Compilers

Licensed under the MIT License