c++26 utility library
built and tested with:
- linux: gcc 16, clang 23
- windows: msvc, clang 23
header only core
miniram: O(1) offset allocator with defragmentation, fully constexpr (inspired by Sebastian Aaltonen's OffsetAllocator)ring_alloc: lock-free ring allocator, contiguous allocationspoly_vector: struct of arrays in a single allocationunion_find: disjoint sets onpoly_vectoroptional: supports references andvoid, monadic operationspool,thread_pool,string_joiner
atomic_fence: manual reset event onstd::atomicwait / notify,atomic_heap_fenceas movable variantglobal_switch: thread safe, reference counted on / off switch for global stateunique_cohandle: owningstd::coroutine_handleextract_awaiter: the awaiter of any awaitable, member or freeoperator co_await
- concepts as values:
CPT(std::integral) - multi dimensional range traits:
md_range_value_t,range2d_over_cpt - trait packs, tuple & variant helpers
CTH_STABLE_*macros always active,CTH_*debug only- capture
std::source_locationandstd::stacktrace - trailing block runs only if the condition holds
CTH_FORMAT_CLASS,CTH_FORMAT_ALIAS,CTH_FORMAT_CPT: generatestd::formatterspecializations for classes, wrapper types and all types of a concept
unique_combine/assign: bipartite matching on 2d ranges- pipeable views:
split_into,drop_stride,transform_call,to_ptr_range
combine, range hashinghash_aggregate: hashes aggregates member wise
not_null,move_ptr
- colored console output:
col_stream - file reading:
file::chop,file::read
coroutine runtime on asio
co::scheduler:asio::io_contexton its own threadsco::executor: spawns tasks, moves execution back onto the scheduler after foreign awaitablesthis_coro::executor,this_coro::wait(duration), native handle waits
portable waitable handles
- native handles: fd (linux),
HANDLE(windows) os::fence: eventfd (linux), event (windows)os::timer: timerfd (linux), high resolution waitable timer (windows), sub millisecond waits (asio'ssteady_timercan't)
windows only
- win32 wrappers without leaking
<Windows.h> cth::win::capture: window capture
cth::dt::miniram ram{1024};
auto const a = ram.allocate(256);
auto const b = ram.allocate(256);
ram.free(a);
auto const report = ram.defragment(); // b moves to offset 0
for(auto const& move : report.moves)
std::memmove(memory + move.dstOffset, memory + move.srcOffset, move.size);cth::co::scheduler scheduler{cth::co::autostart, 2};
cth::co::executor executor{scheduler};
auto task = []() -> cth::co::executor_task<int> {
co_await cth::co::this_coro::wait(std::chrono::microseconds{200});
co_return 42;
};
int const result = cth::co::sync(executor.spawn(task()));from cth/io/file.hpp:
CTH_STABLE_ERR(!file.is_open(), "failed to open file") {
details->add("file: {0}", path.string());
throw details->exception();
}- cmake 4.1+, ninja
- vcpkg with
VCPKG_ROOTset - gcc 16, clang 22+ (libstdc++) or msvc
git clone --recursive https://github.com/codethinki/cth.git
cd cth
cmake --preset gcc_release
cmake --build out/build/gcc_release
ctest --test-dir out/build/gcc_releasegcc_debug,gcc_release,clang_debug,clang_release- windows only:
msvc_debug,msvc_release
building installs the package into out/install/<preset> (target cth_package), point cth_ROOT there:
find_package(cth CONFIG REQUIRED COMPONENTS coro)
target_link_libraries(app PRIVATE cth::coro)api not stable yet, no versioned releases
cth,os,coro- windows only:
win,win_capture