5 Quantities and units library [quantities]

5.2 mp-units module synopses [mp.units.syns]

5.2.2 Module mp_units.core synopsis [mp.units.core.syn]

// mostly freestanding export module mp_units.core; import std; export namespace mp_units { // [qty.utils], utilities // [qty.sym.txt], symbol text enum class character_set : std::int8_t { utf8, portable, default_character_set = utf8 }; template<std::size_t N, std::size_t M> class symbol_text; // [qty.sym.expr], symbolic expressions // [qty.sym.expr.types], types template<typename T, typename... Ts> struct per; template<typename F, int Num, int... Den> requires see below struct power; // [qty.ref], reference // [qty.dim], dimension // [qty.dim.concepts], concepts template<typename T> concept Dimension = see below; template<typename T, auto D> concept DimensionOf = see below; // [qty.dim.types], types template<symbol_text Symbol> struct base_dimension; template<SymbolicConstant... Expr> struct derived_dimension; struct dimension_one; inline constexpr dimension_one dimension_one{}; // [qty.dim.ops], operations consteval Dimension auto inverse(Dimension auto d); template<std::intmax_t Num, std::intmax_t Den = 1, Dimension D> requires(Den != 0) consteval Dimension auto pow(D d); consteval Dimension auto sqrt(Dimension auto d); consteval Dimension auto cbrt(Dimension auto d); // [qty.dim.sym.fmt], symbol formatting struct dimension_symbol_formatting { character_set char_set = character_set::default_character_set; }; template<typename CharT = char, std::output_iterator<CharT> Out, Dimension D> constexpr Out dimension_symbol_to(Out out, D d, const dimension_symbol_formatting& fmt = {}); template<dimension_symbol_formatting fmt = {}, typename CharT = char, Dimension D> consteval std::string_view dimension_symbol(D); // [qty.spec], quantity specification // [qty.spec.concepts], concepts template<typename T> concept QuantitySpec = see below; template<typename T, auto QS> concept QuantitySpecOf = see below; // [qty.spec.types], types // [named.qty], named struct is_kind; inline constexpr is_kind is_kind{}; template<auto...> struct quantity_spec; // not defined template<BaseDimension auto Dim, QSProperty auto... Args> struct quantity_spec<Dim, Args...>; template<DerivedQuantitySpec auto Eq, QSProperty auto... Args> struct quantity_spec<Eq, Args...>; template<NamedQuantitySpec auto QS, QSProperty auto... Args> struct quantity_spec<QS, Args...>; template<NamedQuantitySpec auto QS, DerivedQuantitySpec auto Eq, QSProperty auto... Args> struct quantity_spec<QS, Eq, Args...>; // [derived.qty], derived template<SymbolicConstant... Expr> struct derived_quantity_spec; // [dimless.qty], base quantity of dimension one struct dimensionless; inline constexpr dimensionless dimensionless{}; // [kind.of.qty], kind of template<QuantitySpec Q> requires see below struct kind_of_; template<QuantitySpec auto Q> requires requires { typename kind_of_<decltype(Q)>; } inline constexpr kind_of_<decltype(Q)> kind_of{}; // [qty.spec.ops], operations consteval QuantitySpec auto inverse(QuantitySpec auto q); template<std::intmax_t Num, std::intmax_t Den = 1, QuantitySpec Q> requires(Den != 0) consteval QuantitySpec auto pow(Q q); consteval QuantitySpec auto sqrt(QuantitySpec auto q); consteval QuantitySpec auto cbrt(QuantitySpec auto q); // [qty.spec.hier.algos], hierarchy algorithms // [qty.spec.conv], conversion consteval bool implicitly_convertible(QuantitySpec auto from, QuantitySpec auto to); consteval bool explicitly_convertible(QuantitySpec auto from, QuantitySpec auto to); consteval bool castable(QuantitySpec auto from, QuantitySpec auto to); consteval bool interconvertible(QuantitySpec auto qs1, QuantitySpec auto qs2); // [qty.get.kind], get_kind template<QuantitySpec Q> consteval see below get_kind(Q); // [get.common.qty.spec], get_common_quantity_spec consteval QuantitySpec auto get_common_quantity_spec(QuantitySpec auto... qs) requires see below; // [qty.unit], unit // [qty.unit.mag], magnitude // [qty.unit.mag.concepts], concepts template<typename T> concept MagConstant = see below; template<typename T> concept UnitMagnitude = see below; // [qty.unit.mag.types], types template<symbol_text Symbol, long double Value> requires(Value > 0) struct mag_constant; // [qty.unit.mag.ops], operations template<MagArg auto V> constexpr UnitMagnitude auto mag = see below; template<std::intmax_t N, std::intmax_t D> requires(N > 0) constexpr UnitMagnitude auto mag_ratio = see below; template<MagArg auto Base, int Num, int Den = 1> constexpr UnitMagnitude auto mag_power = see below; // constants inline constexpr struct pi final : mag_constant<{u8"\u03C0" /* U+03c0 GREEK SMALL LETTER PI */, "pi"}, std::numbers::pi_v<long double>> { } pi; inline constexpr auto \u03C0 /* U+03c0 GREEK SMALL LETTER PI */ = pi; // [qty.unit.traits], traits template<Unit auto U> constexpr bool space_before_unit_symbol = true; template<> inline constexpr bool space_before_unit_symbol<one> = false; // [qty.unit.concepts], concepts template<typename T> concept Unit = see below; template<typename T> concept PrefixableUnit = see below; template<typename T> concept AssociatedUnit = see below; template<typename U, auto QS> concept UnitOf = see below; // [qty.unit.types], types // [qty.scaled.unit], scaled template<UnitMagnitude auto M, Unit U> requires see below struct scaled_unit; // [qty.named.unit], named template<symbol_text Symbol, auto...> struct named_unit; // not defined template<symbol_text Symbol, QuantityKindSpec auto QS> requires see below struct named_unit<Symbol, QS>; template<symbol_text Symbol, QuantityKindSpec auto QS, PointOrigin auto PO> requires see below struct named_unit<Symbol, QS, PO>; template<symbol_text Symbol> requires see below struct named_unit<Symbol>; template<symbol_text Symbol, Unit auto U> requires see below struct named_unit<Symbol, U>; template<symbol_text Symbol, Unit auto U, PointOrigin auto PO> requires see below struct named_unit<Symbol, U, PO>; template<symbol_text Symbol, AssociatedUnit auto U, QuantityKindSpec auto QS> requires see below struct named_unit<Symbol, U, QS>; template<symbol_text Symbol, AssociatedUnit auto U, QuantityKindSpec auto QS, PointOrigin auto PO> requires see below struct named_unit<Symbol, U, QS, PO>; // [qty.prefixed.unit], prefixed template<symbol_text Symbol, UnitMagnitude auto M, PrefixableUnit auto U> requires see below struct prefixed_unit; // [qty.common.unit], common template<Unit U1, Unit U2, Unit... Rest> struct common_unit; // [qty.derived.unit], derived template<SymbolicConstant... Expr> struct derived_unit; // [qty.unit.one], one struct one; inline constexpr one one{}; // named derived units of a quantity of dimension one inline constexpr struct percent final : named_unit<"%", mag_ratio<1, 100> * one> { } percent; inline constexpr struct per_mille final : named_unit<symbol_text{u8"\u2030" /* U+2030 PER MILLE SIGN */, "%o"}, mag_ratio<1, 1000> * one> { } per_mille; inline constexpr struct parts_per_million final : named_unit<"ppm", mag_ratio<1, 1'000'000> * one> { } parts_per_million; inline constexpr auto ppm = parts_per_million; // [qty.unit.ops], operations consteval Unit auto inverse(Unit auto u); template<std::intmax_t Num, std::intmax_t Den = 1, Unit U> requires see below consteval Unit auto pow(U u); consteval Unit auto sqrt(Unit auto u); consteval Unit auto cbrt(Unit auto u); consteval Unit auto square(Unit auto u); consteval Unit auto cubic(Unit auto u); // [qty.unit.cmp], comparison template<Unit From, Unit To> consteval bool convertible(From from, To to); // [qty.unit.obs], observers consteval QuantitySpec auto get_quantity_spec(AssociatedUnit auto u); consteval Unit auto get_unit(AssociatedUnit auto u); consteval Unit auto get_common_unit(Unit auto... us) requires see below; // [qty.unit.sym.fmt], symbol formatting enum class unit_symbol_solidus : std::int8_t { one_denominator, always, never, default_denominator = one_denominator }; enum class unit_symbol_separator : std::int8_t { space, half_high_dot, default_separator = space }; struct unit_symbol_formatting { character_set char_set = character_set::default_character_set; unit_symbol_solidus solidus = unit_symbol_solidus::default_denominator; unit_symbol_separator separator = unit_symbol_separator::default_separator; }; template<typename CharT = char, std::output_iterator<CharT> Out, Unit U> constexpr Out unit_symbol_to(Out out, U u, const unit_symbol_formatting& fmt = {}); template<unit_symbol_formatting fmt = {}, typename CharT = char, Unit U> consteval std::string_view unit_symbol(U); // [qty.ref.concepts], concepts template<typename T> concept Reference = see below; template<typename T, auto QS> concept ReferenceOf = see below; // [qty.ref.syn], class template reference template<QuantitySpec Q, Unit U> struct reference; // [qty.ref.ops], operations template<typename FwdRep, Reference R, RepresentationOf<get_quantity_spec(R{})> Rep = std::remove_cvref_t<FwdRep>> requires(!OffsetUnit<decltype(get_unit(R{}))>) constexpr quantity<R{}, Rep> operator*(FwdRep&& lhs, R r); template<typename FwdRep, Reference R, RepresentationOf<get_quantity_spec(R{})> Rep = std::remove_cvref_t<FwdRep>> requires(!OffsetUnit<decltype(get_unit(R{}))>) constexpr Quantity auto operator/(FwdRep&& lhs, R); template<typename FwdQ, Reference R, Quantity Q = std::remove_cvref_t<FwdQ>> constexpr Quantity auto operator*(FwdQ&& q, R); template<typename FwdQ, Reference R, Quantity Q = std::remove_cvref_t<FwdQ>> constexpr Quantity auto operator/(FwdQ&& q, R); template<Reference R, typename Rep> requires RepresentationOf<std::remove_cvref_t<Rep>, get_quantity_spec(R{})> constexpr auto operator*(R, Rep&&) = delete; template<Reference R, typename Rep> requires RepresentationOf<std::remove_cvref_t<Rep>, get_quantity_spec(R{})> constexpr auto operator/(R, Rep&&) = delete; template<Reference R, typename Q> requires Quantity<std::remove_cvref_t<Q>> constexpr auto operator*(R, Q&&) = delete; template<Reference R, typename Q> requires Quantity<std::remove_cvref_t<Q>> constexpr auto operator/(R, Q&&) = delete; // [qty.ref.obs], observers template<typename Q, typename U> consteval QuantitySpec auto get_quantity_spec(reference<Q, U>); template<typename Q, typename U> consteval Unit auto get_unit(reference<Q, U>); consteval AssociatedUnit auto get_common_reference(AssociatedUnit auto u1, AssociatedUnit auto u2, AssociatedUnit auto... rest) requires see below; template<Reference R1, Reference R2, Reference... Rest> consteval Reference auto get_common_reference(R1 r1, R2 r2, Rest... rest) requires see below; // [qty.rep], representation enum class quantity_character { scalar, complex, vector, tensor }; // [qty.rep.traits], traits // [qty.fp.traits], floating-point template<typename Rep> constexpr bool treat_as_floating_point = see below; // [qty.char.traits], quantity character template<typename T> constexpr bool disable_scalar = false; template<> inline constexpr bool disable_scalar<bool> = true; template<typename T> constexpr bool disable_scalar<std::complex<T>> = true; template<typename T> constexpr bool disable_complex = false; template<typename T> constexpr bool disable_vector = false; // [qty.val.traits], values template<typename Rep> struct representation_values; // [qty.rep.cpos], customization point objects inline namespace unspecified { inline constexpr unspecified real = unspecified; inline constexpr unspecified imag = unspecified; inline constexpr unspecified modulus = unspecified; inline constexpr unspecified magnitude = unspecified; } // [qty.rep.concepts], concepts template<typename T> concept Representation = see below; template<typename T, quantity_character Ch> concept RepresentationOf = see below; // [qty], quantity // [qty.like], interoperability template<typename T> struct quantity_like_traits; // not defined template<typename T> concept QuantityLike = see below; // [qty.syn], class template quantity template<typename T> concept Quantity = see below; template<typename Q, auto QS> concept QuantityOf = see below; template<Reference auto R, RepresentationOf<get_quantity_spec(R)> Rep = double> class quantity; // [qty.delta], construction helper delta template<Reference R> struct delta_; template<Reference auto R> constexpr delta_<decltype(R)> delta{}; // [qty.non.mem.conv], non-member conversions template<Unit auto ToU, see below> requires see below constexpr Quantity auto value_cast(see below q); template<Representation ToRep, see below> requires see below constexpr quantity<see below, ToRep> value_cast(see below q); template<Unit auto ToU, Representation ToRep, see below> requires see below constexpr Quantity auto value_cast(see below q); template<Representation ToRep, Unit auto ToU, see below> requires see below constexpr Quantity auto value_cast(see below q); template<Quantity ToQ, see below> requires see below constexpr Quantity auto value_cast(see below q); template<QuantitySpec auto ToQS, see below> requires see below constexpr Quantity auto quantity_cast(see below q); } // [qty.common.type], std​::​common_type specializations template<mp_units::Quantity Q1, mp_units::Quantity Q2> requires see below struct std::common_type<Q1, Q2>; template<mp_units::Quantity Q, mp_units::Representation Value> requires see below struct std::common_type<Q, Value>; template<mp_units::Quantity Q, mp_units::Representation Value> requires requires { typename std::common_type<Q, Value>; } struct std::common_type<Value, Q> : std::common_type<Q, Value> {}; namespace mp_units { // [qty.pt], quantity point // [qty.pt.orig], point origin // [qty.pt.orig.concepts], concepts template<typename T> concept PointOrigin = see below; template<typename T, auto QS> concept PointOriginFor = see below; // [qty.pt.orig.types], types // [qty.abs.pt.orig], absolute template<QuantitySpec auto QS> struct absolute_point_origin; // [qty.rel.pt.orig], relative template<QuantityPoint auto QP> struct relative_point_origin; // [qty.zeroth.pt.orig], zeroth template<QuantitySpec auto QS> struct zeroth_point_origin_; template<QuantitySpec auto QS> constexpr zeroth_point_origin_<QS> zeroth_point_origin{}; // [qty.def.pt.orig], default template<Reference R> consteval PointOriginFor<get_quantity_spec(R{})> auto default_point_origin(R); // [qty.pt.like], interoperability template<typename T> struct quantity_point_like_traits; // not defined template<typename T> concept QuantityPointLike = see below; // [qty.pt.syn], class template quantity_point template<typename T> concept QuantityPoint = see below; template<typename QP, auto V> concept QuantityPointOf = see below; template<Reference auto R, PointOriginFor<get_quantity_spec(R)> auto PO = default_point_origin(R), RepresentationOf<get_quantity_spec(R)> Rep = double> class quantity_point; // [qty.point], construction helper point template<Reference R> struct point_; template<Reference auto R> constexpr point_<decltype(R)> point{}; // [qty.pt.non.mem.conv], non-member conversions template<Unit auto ToU, see below> requires see below constexpr QuantityPoint auto value_cast(see below qp); template<Representation ToRep, see below> requires see below constexpr quantity_point<see below, see below, ToRep> value_cast(see below qp); template<Unit auto ToU, Representation ToRep, see below> requires see below constexpr QuantityPoint auto value_cast(see below qp); template<Representation ToRep, Unit auto ToU, see below> requires see below constexpr QuantityPoint auto value_cast(see below qp); template<Quantity ToQ, see below> requires see below constexpr QuantityPoint auto value_cast(see below qp); template<QuantityPoint ToQP, see below> requires see below constexpr QuantityPoint auto value_cast(see below qp); template<QuantitySpec auto ToQS, see below> requires see below constexpr QuantityPoint auto quantity_cast(see below qp); }