C++ single-file

Open-source C++ projects categorized as single-file

Top 15 C++ single-file Projects

  • doctest

    The fastest feature-rich C++11/14/17/20/23 single-header testing framework

    Project mention: Unit testing tool suggestions | /r/learnprogramming | 2023-05-07

    I have never used "tools" for unit-tests, only web sites that show the results of the tests or code coverage. For C++ I prefer https://github.com/doctest/doctest but most companies I worked for use Catch2.

  • Magic Enum C++

    Static reflection for enums (to string, from string, iteration) for modern C++, work with any enum type without any macro or boilerplate code

    Project mention: What C++ library do you wish existed but hasn’t been created yet? | /r/cpp | 2023-07-08

    I'm not sure this is quite what you're asking for, but this library has been super helpful to me in the past : https://github.com/Neargye/magic_enum

  • InfluxDB

    Collect and Analyze Billions of Data Points in Real Time. Manage all types of time series data in a single, purpose-built database. Run at any scale in any environment in the cloud, on-premises, or at the edge.

  • Nameof C++

    Nameof operator for modern C++, simply obtain the name of a variable, type, function, macro, and enum

  • robin-hood-hashing

    Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20

    Project mention: Factor is faster than Zig | news.ycombinator.com | 2023-11-10

    In my example the table stores the hash codes themselves instead of the keys (because the hash function is invertible)

    Oh, I see, right. If determining the home bucket is trivial, then the back-shifting method is great. The issue is just that it’s not as much of a general-purpose solution as it may initially seem.

    “With a different algorithm (Robin Hood or bidirectional linear probing), the load factor can be kept well over 90% with good performance, as the benchmarks in the same repo demonstrate.”

    I’ve seen the 90% claim made several times in literature on Robin Hood hash tables. In my experience, the claim is a bit exaggerated, although I suppose it depends on what our idea of “good performance” is. See these benchmarks, which again go up to a maximum load factor of 0.95 (Although boost and Absl forcibly grow/rehash at 0.85-0.9):

    https://strong-starlight-4ea0ed.netlify.app/

    Tsl, Martinus, and CC are all Robin Hood tables (https://github.com/Tessil/robin-map, https://github.com/martinus/robin-hood-hashing, and https://github.com/JacksonAllan/CC, respectively). Absl and Boost are the well-known SIMD-based hash tables. Khash (https://github.com/attractivechaos/klib/blob/master/khash.h) is, I think, an ordinary open-addressing table using quadratic probing. Fastmap is a new, yet-to-be-published design that is fundamentally similar to bytell (https://www.youtube.com/watch?v=M2fKMP47slQ) but also incorporates some aspects of the aforementioned SIMD maps (it caches a 4-bit fragment of the hash code to avoid most key comparisons).

    As you can see, all the Robin Hood maps spike upwards dramatically as the load factor gets high, becoming as much as 5-6 times slower at 0.95 vs 0.5 in one of the benchmarks (uint64_t key, 256-bit struct value: Total time to erase 1000 existing elements with N elements in map). Only the SIMD maps (with Boost being the better performer) and Fastmap appear mostly immune to load factor in all benchmarks, although the SIMD maps do - I believe - use tombstones for deletion.

    I’ve only read briefly about bi-directional linear probing – never experimented with it.

  • tomlplusplus

    Header-only TOML config file parser and serializer for C++17.

    Project mention: how to handle config files in c++? | /r/cpp_questions | 2023-03-06

    Unless you want to make your own config file parser as an exercise (which is a good idea) I'd recommend using toml++.

  • nanobench

    Simple, fast, accurate single-header microbenchmarking functionality for C++11/14/17/20

    Project mention: The issue of unit tests and performance measurements (Benchmark) | /r/cpp | 2023-05-27

    An alternative is tracking the number of instructions a test executes: https://github.com/martinus/nanobench

  • Argh!

    Argh! A minimalist argument handler. (by adishavit)

  • Onboard AI

    Learn any GitHub repo in 59 seconds. Onboard AI learns any GitHub repo in minutes and lets you chat with it to locate functionality, understand different parts, and generate new code. Use it for free at www.getonboard.dev.

  • span-lite

    span lite - A C++20-like span for C++98, C++11 and later in a single-file header-only library

    Project mention: I love building a startup in Rust. I wouldn't pick it again. | /r/programming | 2023-02-18

    Another solution: use std::span (or some alternative implementations if the codebase doesn't use C++20).

  • string-view-lite

    string_view lite - A C++17-like string_view for C++98, C++11 and later in a single-file header-only library

    Project mention: Is there a std::string::split or something similar? | /r/cpp_questions | 2023-03-13

    There are plenty of polyfill libraries that exist for std features like this. I strongly recommend using an existing one that attempts to match the standard closely. For example this one.

  • expected-lite

    expected lite - Expected objects in C++11 and later in a single-file header-only library

    Project mention: Refactoring with C++17 std::optional | /r/cpp | 2023-05-22

    Or nonstd::expected. Personally, I would rather use output parameters and an enum result or a std::variant over std::optional, because at the very least you have the option for more specific error diagnostics.

  • semver

    Semantic Versioning for modern C++ (by Neargye)

  • serializer

    A single header standard C++ serialization framework. (by eyalz800)

  • scope_guard

    A modern C++ scope guard that is easy to use but hard to misuse.

  • ring-span-lite

    ring-span lite - A C++yy-like ring_span type for C++98, C++11 and later in a single-file header-only library

  • Savefile-Saver

    A program to backup all of your game savefiles on your system, neatly, and into a single folder.

  • SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

NOTE: The open source projects on this list are ordered by number of github stars. The number of mentions indicates repo mentiontions in the last 12 Months or since we started tracking (Dec 2020). The latest post mention was on 2023-11-10.

C++ single-file related posts

Index

What are some of the best open-source single-file projects in C++? This list will help you:

Project Stars
1 doctest 5,307
2 Magic Enum C++ 4,058
3 Nameof C++ 1,821
4 robin-hood-hashing 1,455
5 tomlplusplus 1,245
6 nanobench 1,228
7 Argh! 1,205
8 span-lite 475
9 string-view-lite 379
10 expected-lite 325
11 semver 265
12 serializer 179
13 scope_guard 154
14 ring-span-lite 145
15 Savefile-Saver 8
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com