My personal collection of small C++ modules put in this repo as convenient to share between projects.
All modules require C++23's import std. This means at least CMake 3.30 and
Ninja (what version?)
The library is compiled and tested on Linux. Other UNIX systems might work, and some parts might work on Windows.
The library suffesfully compiles on Clang version 20 and 21. GCC (versions 15 and 16) fails to compile it for now, due to what I suspect to be a mixture of my fault and compiler bugs.
Some thing will fail to compile unless you import std alongside importing
these modules. This is due to how C++ standard specifies instantiation context for modules. I am looking into maybe export importing
std in some or all of the modules, but for now I don't so be wary of that.
| Module | Docs | Depends on | Description | Included by default |
|---|---|---|---|---|
| assert | dxx.assert | - | Provides dxx::assert::always/dxx::assert::debug functions. Makes use of <stacktrace> if available |
Yes |
| cstd | dxx.cstd, dxx.cstd.compat, dxx.cstd.fixed | - | Exports some of the things not provided by std.compat module (like stdout/stdin/etc.) Provides aliases for some fixed-width (and other) types |
Yes |
| errors | dxx.errors | - | Fancier exceptions | Yes |
| http | dxx.http | assert, cstd, errors, overload, utils | A feature-poor and possibly incomplete HTTP server implementation built with C++20 coroutines. Supports networking through UNIX sockets only. Supports long polling. See example. | No. Set DXX_WITH_HTTP CMake option to ON to include |
| math | dxx.math, dxx.math.linalg, dxx.math.utils | assert, cstd, utils | Some helpful math functions | No. Set DXX_WITH_MATH CMake option to ON to include |
| overload | dxx.overload | - | Overload pattern with a few bells and whistles | Yes |
| selftest | dxx.selftest | assert, cstd | Simple unit testing. Link against dot-xx::selftest-main if you don't need to define your own main() |
Yes |
| utils | dxx.utils | cstd | Things that are too miscellaneous to have their own module | Yes |
Each module has its own dedicated branch where its source code is located.
The links at the top of this README will take you to branches that contain
corrseponding modules. src/ directory contains the module source code and
test/ directory (if present) contains the unit tests (utilizing
selftest) for the
module.
The reasnoning for such weird (and probably bad) decision is the following: the modules are small enough that they don't deserve a separate repo and an entire organization to hold these repos, but I still want to preserve the ability to use them separately when possible.
Each module branch has its own individual CMakeLists.txt file and could
be used (unless dependent on) without any other module. The CMakeLists.txt
for individual modules are very simple: they do not set any unnecessary flags
(like forcing -stdlib=libc++, turning CMAKE_CXX_MODULE_STD ON or setting
CMAKE_EXPERIMENTAL_CXX_IMPORT_STD). Managing all this is left to the user.
This branch (main) contains no code other than a CMakeLists.txt that pulls
all modules available in this repo via CPM
and a basic selftest executable for library unit-testing.
Local builds without pulling from GitHub are also supported, see below.
Using the whole repo via CPM
CPMAddPackage( "gh:gregthemadmonk/dot-xx#main" )
target_link_libraries( your_target PRIVATE dot-xx::all ) # link all modules (except selftest)
target_link_libraries( your_target PRIVATE dot-xx::math ) # link only math and required
target_link_libraries( your_target PRIVATE dot-xx::selftest ) # link only selftest and requiredUsing only a specific module with CPM
CPMAddPackage(
NAME "dot-xx-selftest"
GITHUB_REPOSITORY "gregthemadmonk/dot-xx"
GIT_TAG "selftest"
)Using only a specific module without CPM
set( DXX_NO_CPM ON )
add_subdirectory( path/to/dot-xx/assert ) # selftest depends on asssert
add_subdirectory( path/to/dot-xx/cstd ) # selftest depends on cstd
add_subdirectory( path/to/dot-xx/selftest ) # the module we needDependency pulling in CMakeLists.txt for individual modules and in main's
CMakeLists.txt is done via CPM.
You can opt out of this by setting DXX_NO_CPM variable in CMake.
In that case you must manually ensure that the modules are added to your project
in correct order (depenant modules after the ones they depend on).
If you're not using main's CMakeLists.txt you must also note that
CPM is not included with individual
modules and must be provided by you.
Can be found here, although can be a bit out-of-date.
Building documentation is supported if DXX_DOXYGEN variable is set in
CMake. To generate documentation, run ninja docs in the build directory.
The command line I personally use:
mkdir build && cd build
CC=clang CXX=clang++ cmake .. -GNinja \
-DCMAKE_CXX_FLAGS='-stdlib=libc++' \
-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD='whatever-the-feature-test-value-is-now' \
-DDXX_SELFTEST=ON \
-DDXX_DOXYGEN=ONDon't forget to initialize the git submodules for CPM to work like this.
Development workflow revolves around git worktrees. You are expected to have
a directory /path/to/dir with subdirectories named after all the modules and
containing them. You then pass -DDXX_LOCAL=/path/to/dir to CMake,
which will make it use your local copies of modules instead of fetching them
from GitHub.
There are no guidelines yet. Open issues and PRs as you wish.