A modern C++23 general-purpose library for self-contained applications
dross is a general-purpose C++23 library of building blocks for applications: value types held together by a dynamic value, including arbitrary precision numbers, TOML reading and writing, platform utilities for the environment, paths and XDG directories, per-thread run loops with the threads, timers and operation queue built on them, and typed notifications delivered on the thread each subscriber chose, within a process or from one process to another through a place such as a Unix domain socket, or, with the optional gRPC part, across machines over gRPC.
- π’ Arbitrary Precision Arithmetic - String-based numbers that do not overflow; a quotient that does not terminate within 4096 digits keeps 34 significant digits
- π§΅ Dynamic Type System - Unified
valuetype usingstd::variant - π§ Platform Utilities - Environment, filesystem, and XDG support on Linux and macOS
- β‘ No Third-Party Dependencies - Only the C++ standard library and the system's threads
- π― Modern C++23 - Concepts for compile-time constraints, and failures returned through
std::expected
- A C++23 compiler and standard library. On Linux, GCC 13β15, or Clang 20β22 with libstdc++ or libc++; on macOS, the Apple Clang of macOS 15 or 26. Getting Started lists the supported pairings and what CI builds.
- CMake 3.20+, or 3.25+ to build with the presets
- gRPC 1.51+ and protobuf 3.21+, for the optional gRPC part only, installed where CMake finds them; dross does not fetch or build them. CI builds the part against Ubuntu 24.04's gRPC 1.51 and against Homebrew's current release
git clone https://github.com/skipbit/dross.git
cd dross# Configure, build and test into build/release
cmake --workflow --preset release
# Install
sudo cmake --install build/release --prefix /usr/localThe presets are debug, release, static, sanitize-address and
sanitize-thread, each building into build/<preset>. The library is shared
by default; the static preset, or -DBUILD_SHARED_LIBS=OFF, builds a static
one. CMake 3.20 to 3.24 has no presets: configure with
cmake -S . -B build/release -DCMAKE_BUILD_TYPE=Release, then run
cmake --build build/release.
The gRPC part, dross::grpc, is built only when asked for, and configuring
stops with the reason when gRPC is missing or too old:
cmake --preset release -DDROSS_WITH_GRPC=ON
cmake --build --preset release# Option 1: find_package (after installation)
find_package(dross REQUIRED)
target_link_libraries(your_target PRIVATE dross::dross)
# Option 2: FetchContent (no installation needed)
include(FetchContent)
FetchContent_Declare(dross
GIT_REPOSITORY https://github.com/skipbit/dross.git
GIT_TAG <version>
)
FetchContent_MakeAvailable(dross)
target_link_libraries(your_target PRIVATE dross::dross)
# Option 3: CPM (no installation needed)
CPMAddPackage("gh:skipbit/dross#<version>")
target_link_libraries(your_target PRIVATE dross::dross)Replace <version> with a tag from
Releases. main is the
development tip, and the ABI can change between 0.x releases.
The gRPC part, from a dross built with it, is asked for as a component, and gRPC is looked for only then:
find_package(dross REQUIRED COMPONENTS grpc)
target_link_libraries(your_target PRIVATE dross::grpc)# Compile flags
pkg-config --cflags dross
# Link flags
pkg-config --libs dross
# Check version
pkg-config --modversion drossdross.pc names the prefix given at configure time. For an install written
elsewhere with cmake --install --prefix, --define-prefix has pkg-config
take the prefix from where it finds dross.pc in <prefix>/lib/pkgconfig:
PKG_CONFIG_PATH=<prefix>/lib/pkgconfig pkg-config --define-prefix --cflags --libs drossdross.pc describes the library without the gRPC part, which is used
through find_package.
# Using pkg-config
g++ -std=c++23 $(pkg-config --cflags dross) main.cpp $(pkg-config --libs dross)
# Or manually
g++ -std=c++23 -I/usr/local/include main.cpp -L/usr/local/lib -ldross#include <dross/dross.h>
int main()
{
// Arbitrary precision arithmetic
dross::number big_num{"99999999999999999999999999999999999999"};
dross::number result = big_num * big_num; // No overflow!
// Dynamic typing. dictionary has no initializer-list constructor, so
// entries are assigned after construction.
dross::dictionary config;
config["name"] = dross::string("dross");
config["version"] = dross::string("0.1.0");
config["features"] = dross::array{dross::string{"fast"}, dross::string{"safe"}};
config["release_date"] = dross::timestamp{2024, 1, 21, 15, 30, 0, dross::timezone::utc()};
dross::value root = config;
// Platform utilities. The XDG accessors are instance methods, and the
// application name is already part of what they return.
dross::xdg app{"myapp"};
if (auto config_dir = app.config_home()) {
dross::path app_config = dross::path{*config_dir}.append("config.toml");
}
}boolean- Type-safe boolean operations with logical operatorsnumber- Arbitrary precision arithmetic with string-based storagestring- UTF-8 text held as bytes, with byte-oriented operationstimestamp- Date and time handling with timezone supporttimezone- Type-safe timezone representation with ISO 8601 supportarray- Dynamic arrays with value semanticsdictionary- Key-value containersdata- Byte buffer, converted to and from strings byte for bytevalue- Polymorphic type holding any supported typevalue_traits- How a type becomes avalueand comes back from one, given for dross's own types, numbers,std::stringand standard containerserror- Astd::error_codewith its category, returned throughstd::expected
toml- TOML parsing into adictionaryand serialization back to TOML
environment- Environment variable accesspath- Filesystem operations with error handlingxdg- XDG Base Directory specification support
ipc::unix_socket- A place where processes meet: a Unix domain socket at a pathipc::grpc_address/ipc::grpc_target- In the optional gRPC part, a place to listen at and one to connect to over gRPC, each with the credentials the user gives; only dross talks to dross thereipc::message_channel- One connection between two processes, carrying whole messages, and what it tells throughmessage_channel_eventsipc::message_acceptor- What listens at a place, telling of each connection it takes throughmessage_acceptor_eventsipc::message_connector- What connects to a place, one try at a timeipc::message_listenable_place_type/ipc::message_connectable_place_type- Concepts for a place that can be listened at or connected to, so that a broadcaster can be published at, or a listener can hear through, a place of any type that satisfies them
runloop- Per-thread task queue, so work can be handed to a specific threadthread- A handle to an OS thread, running a loop the library drives, a one-shot body, or one its owner drivestimer- A callback installed on a run loop, firing once or on an intervaloperation_queue- A fixed set of worker threads, each running its own loop, taking submitted tasks from one shared queue by priority, and in the order they were submitted within one priority, each only once the tasks it runs after have returnedoperation_result- What a task given tooperation_queue::enqueue()returned, to wait on and read as its own type
topic- The name a notification is sent under and the type of value it carriesbroadcaster- Sends notifications within the process, and, when published at a place, to listeners in other processes too; it does nothing elselistener- Subscribes to one broadcaster's notifications, in this process or in another, and does not sendlink_event- What happened to a listener's connection to another process: connected, disconnected, or a value its type could not be made fromdelivery- Where a subscriber's function runs: on a run loop, on the sending thread, or on an operation queue's workersubscription- The right to go on receiving, which ends when it is reset or destroyednotification- What one call tonotify()sent, through which its deliveries not yet started can be cancellednotify_options- Hownotify()sends, such as deferring the subscribers that run on the sending thread until it returnsobservable- A value its owner thread changes, whose changes reach the functions given towhen_changed(), and which other threads set through aproxy
π API Reference & User Guide
The documentation includes:
- π API Reference - The type system and the platform layer
- π User Guide - An overview of the library's conventions
- π‘ Examples - Code examples across the modules
dross follows modern C++ best practices:
- Pimpl Idiom - Types keep their representation behind an opaque pointer, apart from
error,path,xdg,ipc::unix_socket,ipc::grpc_address,ipc::grpc_target,timestamp,timezoneand thedataiterators, which hold theirs directly, and theipc::message_*interfaces, which a part implements; the ABI can change in any 0.x release - Value Semantics - The value types are copyable and assignable;
environmentexposes only static members - Error Handling - Failures are returned through
std::expectedandstd::optional. Where a call throws, lets an exception through, or reports its outcome another way, its comment in the public headers says so - Type Safety - Concepts for compile-time constraints
The tests use GoogleTest:
# Run all tests, in the tree the release preset built
ctest --preset release
# Run specific test patterns
ctest --preset release -R number
./build/release/test/dross_test --gtest_filter="number_test.*"
# Verbose output
ctest --preset release -V- Format - JSON, XML, YAML
- Concurrency - Coroutines
- Multimedia - Image processing, color management, transformations
- Application Support - CLI parsing, logging, preferences
See the Contributing guide for the workflow, and CODINGSTYLE.md for coding guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ by Yuma Endo