Skip to content
Welcome to the new CppUtils documentation!

Welcome to CppUtils! This guide walks you through setting up your environment, integrating the library into your projects using XMake, and compiling a first example with CppUtils.


CppUtils is built with C++26 and is fully modular (import CppUtils...;, import std;).

  • C++ compiler: A C++26 compliant compiler with standard library module support (import std;) - Clang / LLVM is the recommended compiler tested in continuous integration.
  • Build system: XMake (native support for C++20 modules and package management - special thanks to Arthapz who implemented modules support in XMake).

You can either integrate CppUtils into an existing project via the personal XMake package repository (MorganCaron/xmake-repo) or build and test it locally from source.

  1. Add the XMake repository to your xmake.lua

    Add the CppUtils XMake repository to your project configuration and declare the dependency:

    xmake.lua
    add_repositories("xmake-repo https://github.com/MorganCaron/xmake-repo.git")
    add_requires("CppUtils 0.1.*") -- pinned version recommended (or "CppUtils" for latest)
  2. Add CppUtils to your project

    Configure your executable target for C++26 and add the CppUtils dependency:

    xmake.lua
    target("MyApplication")
    set_kind("binary")
    set_languages("c++26")
    add_files("src/*.cpp")
    add_packages("CppUtils", { public = true })
  3. Configure and build

    Configure with the LLVM toolchain (or MSVC on Windows) depending on your runtime needs:

    Fenêtre de terminal
    # Shared runtime (recommended for development: fast linking and lightweight binaries)
    xmake f --toolchain=llvm --runtimes="c++_shared"
    xmake
    # Or static runtime (recommended for deployment: self-contained binary)
    xmake f --toolchain=llvm --runtimes="c++_static"
    xmake
    • c++_shared (development): faster incremental linking and lightweight binaries by dynamically linking against the host machine’s installed libc++.
    • c++_static (deployment): produces a self-contained binary with no dependency on the target machine’s libc++.

To verify that your project is properly configured and that CppUtils is successfully imported, compile and run any of these three examples:

A bidirectional associative map providing constant-time O(1) lookup:

main.cpp
import CppUtils;
int main()
{
using namespace std::literals;
// Bidirectional map associating HTTP status codes and constant descriptions
const auto httpCodes = CppUtils::Container::BidirectionalMap<int, std::string_view>{
std::pair{200, "OK"sv},
std::pair{404, "Not Found"sv},
std::pair{500, "Internal Server Error"sv}
};
std::println("Code 200 -> {}", httpCodes.left(200));
std::println("'Not Found' -> {}", httpCodes.right("Not Found"sv));
return 0;
}
Output
Code 200 -> OK
'Not Found' -> 404