Skip to content

mp_units::derived_dimension

A dimension of a derived quantity

Synopsis

Declared in <mp-units/framework/dimension.h>

template</* implementation-defined */... Expr>
struct derived_dimension final

Description

Derived dimension is an expression of the dependence of a quantity on the base quantities of a system of quantities as a product of powers of factors corresponding to the base quantities, omitting any numerical factors.

Instead of using a raw list of exponents this library decided to use symbolic expression syntax to make types more digestable for the user. The positive exponents are ordered first and all negative exponents are put as a list into the per<...> class template. If a power of exponent is different than 1 the dimension type is enclosed in power<Dim, Num, Den> class template. Otherwise, it is just put directly in the list without any wrapper. There is also one special case. In case all of the exponents are negative than the dimension_one being a dimension of a dimensionless quantity is put in the front to increase the readability.

For example:

inline constexpr auto dim_frequency = inverse(dim_time);
inline constexpr auto dim_speed = dim_length / dim_time;
inline constexpr auto dim_acceleration = dim_speed / dim_time;
inline constexpr auto dim_force = dim_mass * dim_acceleration;
inline constexpr auto dim_energy = dim_force * dim_length;
  • dim_frequency is of type derived_dimension<dimension_one, per<dim_time>>
  • dim_speed is of type derived_dimension<dim_length, per<dim_time>>
  • dim_acceleration is of type derived_dimension<dim_length, per<power<dim_time, 2>>>
  • dim_force is of type derived_dimension<dim_length, dim_mass, per<power<dim_time, 2>>>
  • dim_energy is of type derived_dimension<power<dim_length, 2>, dim_mass, per<power<dim_time, 2>>>

Note

A common convention in this library is to assign the same name for a type and an object of this type. Besides defining them user never works with the dimension types in the source code. All operations are done on the objects. Contrarily, the dimension types are the only one visible in the compilation errors. Having them of the same names improves user experience and somehow blurs those separate domains.

Note

User should not instantiate this type! It is not exported from the C++ module. The library will instantiate this type automatically based on the dimensional arithmetic equation provided by the user.

Non-Member Functions

NameDescription
cbrt
inverse
operator*scaled_unit specializations have priority in this operation. This means that the library framework prevents passing it as an element to the derived_unit. In such case only the reference unit is passed to the derived unit and the magnitude remains outside forming another scaled unit as a result of the operation.
operator/scaled_unit specializations have priority in this operation. This means that the library framework prevents passing it as an element to the derived_unit. In such case only the reference unit is passed to the derived unit and the magnitude remains outside forming another scaled unit as a result of the operation.
operator<<Stream insertion operator
operator==Equality operator
pow
pow
sqrt

Template Parameters

NameDescription
Dsa parameter pack consisting tokens allowed in the dimension specification (base dimensions, dimension_one, power<Dim, Num, Den>, per<...>)