compat.argparse
#includeargparse — header-only argument parser for modern C++
#include <argparse/argparse.hpp>
mcpp add compat.argparse@3.2
用法
来自本仓库自己的测试项目 —— CI 真的编译并运行过,不是为了网站写的。
// Behavioral test — compat.argparse parses a command line, it does not merely
// include.
//
// argv is written by hand rather than taken from the runner, so the assertions
// are about argparse's behaviour and not about how `mcpp test` invokes a
// binary. No `import std;`: argparse.hpp is a textual header over the standard
// library.
#include <argparse/argparse.hpp>
#include <iostream>
#include <string>
#include <vector>
int main() {
argparse::ArgumentParser program("renderer", "0.1.0");
program.add_argument("model").help("path to the glTF model");
program.add_argument("--width").default_value(1280).scan<'i', int>();
program.add_argument("--validate").default_value(false).implicit_value(true);
const std::vector<std::string> argv{"renderer", "scene.gltf", "--width", "1920", "--validate"};
try {
program.parse_args(argv);
// …
tests/examples/argparse/tests/parse.cpp · 项目 tests/examples/argparse
openkal
| 目标 | 结果 | 环境 | 测试项目 | 首条诊断 |
|---|---|---|---|---|
| x86_64-linux-gnu | runs | posix | argparse | |
| x86_64-windows-musl | runs | posix | argparse |
测量方式
2026-09-23 由 tests/openkal/compat.py 测得,使用 openkal-llvm-runtime 0.15.1、llvm@22.1.8、mcpp 2026.9.21.3。测试项目没有自行选择平台依赖。 上方徽章是所有已测目标里最严格那个的结果 —— 上表列出每个目标各自的环境。
构建
- targets
argparse (lib)- language
c++23- C standard
c11- import std
- no
- include dirs
*/include
源文件 (1)
mcpp_generated/argparse_anchor.c
生成的文件
mcpp_generated/argparse_anchor.c