这是一个编译时、仅包含头文件的维度分析和单位转换库,基于 C++14 而构建,不依赖任何其他库。
units 是一个编译时、只包含头文件的维度分析和单位转换库,不依赖任何其他库。units 将物理量表示为类型。一个量是带有单位(例如 meters、feet、seconds)的值,其行为类似于它所包装的数字。相容单位之间的转换在编译时是隐式的,且会被解析;尺度不一致的表达式无法编译。
cpp #include // 所有内容;或者 , , ... 表示子集 using namespace units; using namespace units::literals; // _m, _s, _kg, ... 等字面量
cpp meters local(5.0); // 仅有名称,推断出米 meters<> m; // 默认表示法 meters as_float(5.0f); // 显式表示法 // void f(meters q); // 语法错误:参数没有可从中推断出的初始化器 // meters make(); // 语法错误:返回类型没有可从中推断出的初始化器
Write the type explicitly on the left when the compiler should confirm the dimensional analysis: naming
the result type makes a mismatch a compile error rather than an accepted `auto` deduction.
``` cpp 平方米 area = 15.0_m * 5.0_m; // 结果是面积暂无开放 Issues,或尚未同步最近议题。