mcpp index

mpusz.mp-units

import

Physical quantities and units through the upstream mp_units C++ modules

import mp_units.core;
mcpp add mpusz.mp-units@2.5.0

Usage

From this repository's own test project — built and run by CI, not written for the website.

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 · project tests/examples/mp-units-module

Build

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

Sources (3)

  • */src/core/mp-units-core.cppm
  • */src/systems/mp-units-systems.cppm
  • */src/mp-units.cppm

Versions

VersionPlatforms Mirrorssha256
2.5.0 latest LinuxWindowsmacOS source a6bd48bee699…