A collection of C++ 23 utilities I reuse across projects - like assertions, hashing, compression wrappers, literal helpers, random utilities, etc.
- General Information
- Technologies Used
- Features
- Setup
- Usage
- Project Status
- Room for Improvement
- Acknowledgements
- License
A C++ 23 utility library. It’s intentionally opinionated and minimal.
Why I made it:
- I wanted a single place for safe, well-documented utility code that compiles with modern C++ and fits the no surprises philosophy.
- clang 20.1.8
- snappy 1.2.2-2
- zstd 1.5.7-2
- ctre 3.10.0-1 (my fork of it with fixed includes)
- glaze 5.7.2-1
stdfunc:makeVariantContainerto make specified container with passed values.bitsToBytes,lengthOfNumber,isSpaceconstexprhelpers.sanitizeStringconstexprto trim spaces and comment and return view to trimmed part of passed string.
float16_ttype andstd::numeric_limits<float16_t>andstd::formatter<float16_t>.uint128_ttype andmakeU128to convert string.- Literal helpers under
stdfunc::literals:_bbyte literal,_bytescompile-time byte arrays,_u128string touint128_t.
- Colored terminal ASCII-code constants in
stdfunc::color. - Debug helpers under
stdfunc:trapandassertthat are active withDEBUGdefine (thread ID, stack trace, colored output).
- Compression wrappers under
stdfunc::compress:compress::textusessnappycompression.compress::datauseszstd.
- Decompression wrappers under
stdfunc::decompress:decompress::textusessnappycompression.decompress::datauseszstd.
- Concepts under
stdfunc:has_common_type,is_container,is_struct,is_lambda,is_formattable.
- File system helpers under
stdfunc::filesystem:getApplicationDirectoryAbsolutePathgetPathsByRegexp- runtimestd::regexand compile-timectreoverload.
- Hashing under
stdfunc::hash:hash::weak(FNV-1A) for 32bits, 64bits and 128bits.hash::balanced(rapidhash) for 64bits and (xxHash3) for 128bits.
- Random utilities under
stdfunc::random:random::number::weak(constexpr-friendlyxor-shift*generator for 32bits, 64bits and 128bits).random::number::balanced(runtime 32bits or 64bits depending on build target).random::valuefor random value reference from container.random::viewfor infinite view of random values reference from container.random::fillto fill container with random values.
- Meta/ reflection for aggregate
structs understdfunc::meta:is_reflectableconcept.iterateStructTopMostFieldsto iterate reflectablestructwith callback.hasMemberWithNameconstevalto check if reflectablestructhas a member with name.
- A set of macros for attributes (
FORCE_INLINE,CONST,PACKED, etc.).
Mostly constexpr where feasible.
This project provides multiple hashing tiers optimized for different goals such as compile-time evaluation, runtime speed, and cryptographic security.
| Level | Goal | Properties | Example Algorithms |
|---|---|---|---|
| Weak | Compile-time / minimal overhead | constexpr, extremely fast, tiny binary size, not collision resistant |
FNV-1a |
| Balanced | General-purpose hashing | Very fast, good distribution, suitable for most applications | xxHash3, rapidhash |
| Strong | Cryptographic hashing | Collision resistant, suitable for security-sensitive hashing | BLAKE2 |
| Robust | Password / key derivation | Memory-hard, resistant to brute-force and GPU attacks | Argon2 |
- Weak hashes prioritize compile-time evaluation and minimal overhead.
- Balanced hashes provide excellent speed and quality for general use.
- Strong hashes provide cryptographic guarantees such as collision resistance.
- Robust algorithms are designed for password hashing and key derivation and intentionally trade speed for security.
This project provides multiple tiers of random number generators (RNGs) optimized for different goals, such as compile-time evaluation, runtime speed, statistical quality, and cryptographic security.
| Level | Goal | Properties | Example Generators |
|---|---|---|---|
| Weak | Compile-time / lightweight | constexpr, extremely fast, minimal state, small binary size, not cryptographically secure |
xorshift* (xorshift multiply) |
| Balanced | General-purpose RNG | High-quality randomness, suitable for simulations and games, platform-portable | std::mt19937_64 (64-bit), fallback to std::mt19937 if 64-bit not supported |
| Strong | Cryptographically secure RNG | Produces unpredictable, high-entropy values suitable for cryptography, keys, nonces, and security-sensitive tasks | OpenSSL RAND_bytes() |
| Robust | Cryptographically secure / system RNG | Resistant to prediction and attacks, suitable for security-critical tasks | /dev/urandom on Linux (platform-specific secure sources for other OSes) |
- Weak RNGs are ideal for quick computations, games, or compile-time randomness, but should not be used where security or high-quality randomness is required.
- Balanced RNGs offer a good compromise between speed, quality, and portability; suitable for simulations, procedural generation, and most general tasks.
- Strong RNGs provide excellent statistical quality and extremely long periods; useful for simulations and scientific computations requiring high-quality randomness.
- Robust RNGs use system entropy or cryptographically secure sources to ensure unpredictability; intended for security-sensitive applications like key generation or cryptography.
Requirements/ dependencies:
- C++ 23-capable compiler.
- Add the following libraries if you use the related subsystems:
rapidhashorxxhashfor 64bitshash::balancedxxhashfor 128bitshash::balancedsnappyforcompress::text/decompress::textzstdlibrary forcompress::data/decompress::datactre/ctllfor compile-timegetPathsByRegexpglazeformeta::*
Installation:
- See
config.shfor what to include and what to compile.
Quick examples demonstrating the most common helpers.
Parsing decimal into 128bits:
#include "std128.hpp"
uint128_t v = stdfunc::makeU128( "6C62272E07BB014262B821756295C58D" ); // Hex without 0xColored output:
#include "stdcolor.hpp"
std::println( "{}GREEN BOLD TEXT{}", stdfunc::color::g_green, stdfunc::color::g_reset );Debug trap/assert:
#include "stddebug.hpp" // only active with DEBUG define
stdfunc::assert( false, "Always {}", "fail" );
stdfunc::trap( "Fatal: {}", l_message );Compression (text - fast and good byte-wise compression; data - good data compression):
#include "stdcompress.hpp"
#include "stddecompress.hpp"
auto l_compressed = stdfunc::compress::text( "Hello, World!\n" );
if ( l_compressed ) {
writeBinaryFile( "hello.txt", l_compressed.value() );
auto l_decompressed = stdfunc::decompress::text( l_compressed.value() );
std::println( "{}", l_decompressed );
}Hashing:
#include "stdhash.hpp"
const std::vector< std::byte > data = /* ... */;
auto l_v32 = stdfunc::hash::weak< uint32_t >( std::span( data ) );
auto l_v128 = stdfunc::hash::balanced< uint128_t >( std::span( data ) );RNG helpers:
#include "stdrandom.hpp"
stdfunc::random::g_engine.seed( 12345 ); // Will affect only balanced
int128_t l_number = stdfunc::random::number::weak< uint128_t >( 0, 100 );
int l_number2 = stdfunc::random::number::balanced< int >( 0, 100 );Utility helpers:
#include "stdfunc.hpp"
auto l_container = stdfunc::makeVariantContainer< std::vector >( 1, "str", 3.0f ); // Will hold std::variant of all passed types
size_t l_bytes = stdfunc::bitsToBytes( 13 ); // -> 2Project is: in progress.
Room for improvement:
- Make
hash::balancedconstexpr - Add hex input support to
makeU128and fix edge-case parsing/ overflow handling. - Make
compress::text/compress::data/decompress::*constexprwhere practical or provide no-runtime stubs for compile-time builds.
To do:
- Add small examples in
examples/demonstrating common integration patterns. - Implement
stdfunc::system
- Compression choices are inspired by practical, fast compressors (
snappy,zstd). - Reflection helpers lean on
glazereflection. - Compile-time regexp code uses
ctre/ctll.
This project is open source and available under the GNU Affero General Public License v3.0.