mpusz.mp-units
importPhysical quantities and units through the upstream mp_units C++ modules
import mp_units.core;
mcpp add mpusz.mp-units@2.5.0
用法
來自本倉庫自己的測試專案 —— CI 真的編譯並執行過,不是為了網站寫的。
import std;
import mp_units;
#include "../src/quantity_bridge.h"
using namespace mp_units;
using namespace mp_units::si::unit_symbols;
template<class Left, class Right>
concept Addable = requires(Left left, Right right) { left + right; };
static_assert(1 * km == 1000 * m);
static_assert(!Addable<decltype(1 * m), decltype(1 * s)>);
static_assert((120 * km / (2 * h)).numerical_value_in(km / h) == 60);
static_assert(quantity{std::chrono::minutes{2}} == 120 * s);
int main() {
if (add_distance(20 * m, 22 * m) != 42 * m) return 1;
if (std::format("{}", 42 * m) != "42 m") return 2;
if (std::format("{}", 2 * ohm) != "2 \xce\xa9") return 3;
return 0;
}
tests/examples/mp-units-module/tests/units.cpp · 專案 tests/examples/mp-units-module
建置
- modules
mp_units.core, mp_units.systems, mp_units- targets
mp-units (lib)- language
c++23- import std
- yes
- include dirs
*/src/core/include, */src/systems/include
原始檔 (3)
*/src/core/mp-units-core.cppm*/src/systems/mp-units-systems.cppm*/src/mp-units.cppm
版本
| 版本 | 平台 | 鏡像 | sha256 |
|---|---|---|---|
2.5.0 最新 |
LinuxWindowsmacOS | 來源 | a6bd48bee699… |