5 Quantities and units library [quantities]
export module mp_units.core;
import std;
export namespace mp_units {
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;
template<typename T, typename... Ts>
struct per;
template<typename F, int Num, int... Den>
requires see below
struct power;
template<typename T>
concept Dimension = see below;
template<typename T, auto D>
concept DimensionOf = see below;
template<symbol_text Symbol>
struct base_dimension;
template<SymbolicConstant... Expr>
struct derived_dimension;
struct dimension_one;
inline constexpr dimension_one dimension_one{};
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);
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);
template<typename T>
concept QuantitySpec = see below;
template<typename T, auto QS>
concept QuantitySpecOf = see below;
struct is_kind;
inline constexpr is_kind is_kind{};
template<auto...>
struct quantity_spec;
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...>;
template<SymbolicConstant... Expr>
struct derived_quantity_spec;
struct dimensionless;
inline constexpr dimensionless dimensionless{};
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{};
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);
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);
template<QuantitySpec Q>
consteval see below get_kind(Q);
consteval QuantitySpec auto get_common_quantity_spec(QuantitySpec auto... qs)
requires see below;
template<typename T>
concept MagConstant = see below;
template<typename T>
concept UnitMagnitude = see below;
template<symbol_text Symbol, long double Value>
requires(Value > 0)
struct mag_constant;
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;
inline constexpr struct pi final :
mag_constant<{u8"\u03C0" , "pi"},
std::numbers::pi_v<long double>> {
} pi;
inline constexpr auto \u03C0 = pi;
template<Unit auto U>
constexpr bool space_before_unit_symbol = true;
template<>
inline constexpr bool space_before_unit_symbol<one> = false;
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;
template<UnitMagnitude auto M, Unit U>
requires see below
struct scaled_unit;
template<symbol_text Symbol, auto...>
struct named_unit;
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>;
template<symbol_text Symbol, UnitMagnitude auto M, PrefixableUnit auto U>
requires see below
struct prefixed_unit;
template<Unit U1, Unit U2, Unit... Rest>
struct common_unit;
template<SymbolicConstant... Expr>
struct derived_unit;
struct one;
inline constexpr one 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" , "%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;
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);
template<Unit From, Unit To>
consteval bool convertible(From from, To to);
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;
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);
template<typename T>
concept Reference = see below;
template<typename T, auto QS>
concept ReferenceOf = see below;
template<QuantitySpec Q, Unit U>
struct reference;
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;
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;
enum class quantity_character { scalar, complex, vector, tensor };
template<typename Rep>
constexpr bool treat_as_floating_point = see below;
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;
template<typename Rep>
struct representation_values;
inline namespace unspecified {
inline constexpr unspecified real = unspecified;
inline constexpr unspecified imag = unspecified;
inline constexpr unspecified modulus = unspecified;
inline constexpr unspecified magnitude = unspecified;
}
template<typename T>
concept Representation = see below;
template<typename T, quantity_character Ch>
concept RepresentationOf = see below;
template<typename T>
struct quantity_like_traits;
template<typename T>
concept QuantityLike = see below;
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;
template<Reference R>
struct delta_;
template<Reference auto R>
constexpr delta_<decltype(R)> delta{};
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);
}
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 {
template<typename T>
concept PointOrigin = see below;
template<typename T, auto QS>
concept PointOriginFor = see below;
template<QuantitySpec auto QS>
struct absolute_point_origin;
template<QuantityPoint auto QP>
struct relative_point_origin;
template<QuantitySpec auto QS>
struct zeroth_point_origin_;
template<QuantitySpec auto QS>
constexpr zeroth_point_origin_<QS> zeroth_point_origin{};
template<Reference R>
consteval PointOriginFor<get_quantity_spec(R{})> auto default_point_origin(R);
template<typename T>
struct quantity_point_like_traits;
template<typename T>
concept QuantityPointLike = see below;
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;
template<Reference R>
struct point_;
template<Reference auto R>
constexpr point_<decltype(R)> point{};
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);
}