アルゴリズムとデータ構造のヘッダオンリー集。各実装は include/toolbox/ 以下に置き、
テストは tests/ 以下に置く。ビルド・テストは CMake + CTest で行う。
- CMake 3.20 以上
- C++20 対応コンパイラ(GCC / Clang)
- (整形チェックを行う場合)clang-format 21
CMake プリセットを利用する。
# 構成(Debug + テスト有効)
cmake --preset default
# ビルド
cmake --build --preset default
# テスト実行
ctest --preset default利用可能なプリセット:
| プリセット | 内容 |
|---|---|
default |
Debug ビルド + テスト |
release |
Release ビルド + テスト |
asan |
AddressSanitizer + UndefinedBehaviorSanitizer 付き |
サニタイザ付きで実行する場合:
cmake --preset asan
cmake --build --preset asan
ctest --preset asan- 実装を
include/toolbox/<category>/<algorithm>/<algorithm>.hppに置く。 - テストを
tests/<category>/<algorithm>/main.cppに置く。- ライブラリのヘッダはすべて
#include "toolbox/..."の形で参照する (include ルートはinclude/)。 - テストヘルパは
#include "utils/test_util.hpp"で参照する (tests/が include パスに入っている)。 - テストランナは
tests/utils/test_util.hppのtoolbox::test_utils::run_testsを使う。
- ライブラリのヘッダはすべて
- これだけでよい。
main.cppは CMake が自動検出し、<ディレクトリ名>_testという名前のテストとして登録する(CMakeLists.txtの編集は不要)。
自動検出は
file(GLOB_RECURSE ... CONFIGURE_DEPENDS)で行っている。ファイルを 追加・削除した後は、再度cmake --buildすれば構成が更新される。
.clang-format(Google ベース)に従う。CI で整形チェックが走る。
# 差分チェック(CI と同じ)
find include tests \( -name '*.hpp' -o -name '*.cpp' \) -print0 \
| xargs -0 clang-format --dry-run --Werror
# 一括整形
find include tests \( -name '*.hpp' -o -name '*.cpp' \) -print0 \
| xargs -0 clang-format -iGitHub Actions で以下を実行する(.github/workflows/)。
tests.yml— GCC / Clang それぞれでビルド + CTest、加えて ASan + UBSan 実行。format.yml— clang-format による整形チェック。