statcpp は C++17 ヘッダーオンリーライブラリです。ヘッダーファイルをインクルードパスに追加するだけで使用できます。
英語版と日本語コメント版の両方が利用可能です。お好みのバージョンをお選びください。
- C++17 対応コンパイラ
- GCC 7.0 以上
- Clang 5.0 以上
- Apple Clang 9.0 以上
- CMake 3.14 以上(オプション、テストやサンプルをビルドする場合)
- macOS + Apple Clang 17.0.0
- macOS + GCC 15 (Homebrew)
- Ubuntu 24.04 ARM64 + GCC
最もシンプルな方法です。include/(英語版)または include-ja/(日本語版)ディレクトリをプロジェクトにコピーして使用します。
# statcpp を任意の場所にクローン
git clone https://github.com/mitsuruk/statcpp.git
# include ディレクトリをプロジェクトにコピー
# 日本語版
cp -r statcpp/include-ja /path/to/your/project/include
# 英語版
cp -r statcpp/include /path/to/your/project/コンパイル時にインクルードパスを指定:
g++ -std=c++17 -I/path/to/your/project/include your_program.cpp -o your_programシステム全体または特定の場所にインストールして使用する方法です。
# リポジトリをクローン
git clone https://github.com/mitsuruk/statcpp.git
cd statcpp
# ビルドディレクトリを作成してインストール(日本語版)
mkdir build
cd build
cmake .. -DSTATCPP_USE_JAPANESE=ON
sudo cmake --install .
# 英語版をインストールする場合(デフォルト)
cmake ..
sudo cmake --install .デフォルトでは /usr/local/include/ にインストールされます。
カスタムインストール先を指定する場合:
cmake -DCMAKE_INSTALL_PREFIX=/your/custom/path ..
cmake --install .| オプション | デフォルト | 説明 |
|---|---|---|
STATCPP_USE_JAPANESE |
OFF | 日本語コメント版ヘッダーを使用 |
STATCPP_BUILD_TESTS |
ON | テストスイートをビルド |
STATCPP_ENABLE_SANITIZERS |
OFF | AddressSanitizer と UndefinedBehaviorSanitizer を有効化 |
既存の CMake プロジェクトにサブディレクトリとして追加する方法です。
# CMakeLists.txt
add_subdirectory(external/statcpp)
target_link_libraries(your_target PRIVATE statcpp)CMake 3.14 以降では、FetchContent を使って自動的にダウンロードして使用できます。
include(FetchContent)
FetchContent_Declare(
statcpp
GIT_REPOSITORY https://github.com/mitsuruk/statcpp.git
GIT_TAG main # または特定のタグ/コミット
)
FetchContent_MakeAvailable(statcpp)
target_link_libraries(your_target PRIVATE statcpp)インストール後、ヘッダーファイルは /usr/local/include/statcpp/(またはカスタムプレフィックス)に配置されます。
statcpp/ プレフィックス付きでヘッダーをインクルードします:
g++ -std=c++17 your_program.cpp -o your_program#include "statcpp/basic_statistics.hpp"以下の簡単なプログラムでインストールを確認できます。
#include <iostream>
#include <vector>
#include "statcpp/basic_statistics.hpp"
int main() {
std::vector<double> data = {1.0, 2.0, 3.0, 4.0, 5.0};
double avg = statcpp::mean(data.begin(), data.end());
std::cout << "平均: " << avg << std::endl; // 出力: 平均: 3
return 0;
}コンパイルと実行:
g++ -std=c++17 -I/path/to/statcpp/include test.cpp -o test
./test最新版のコンパイラにアップグレードしてください。
# macOS (Homebrew)
brew install gcc
# Ubuntu/Debian
sudo apt-get install g++-9
# 特定バージョンを指定してコンパイル
g++-9 -std=c++17 your_program.cpp -o your_programコンパイル時に -I オプションでパスを明示的に指定してください。
g++ -std=c++17 -I/usr/local/include your_program.cpp -o your_programCMAKE_PREFIX_PATH を設定してください。
cmake -DCMAKE_PREFIX_PATH=/your/custom/install/path ..