Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::quantity< QuantityType, Rep > Class Template Reference

A class representing a quantity of a physical units type. More...

Inheritance diagram for arene::base::quantity< QuantityType, Rep >:
Inheritance graph

Public Member Functions

constexpr quantity () noexcept
 Default construct with a default-constructed representation value.
 
template<typename OtherQuantityType, typename OtherRep, constraints< std::enable_if_t< quantity_detail::is_implicitly_convertible_v< OtherQuantityType, QuantityType > >, std::enable_if_t< quantity_detail::scaled_value_in_range_v< OtherQuantityType, OtherRep, QuantityType, Rep > > > = nullptr>
constexpr quantity (quantity< OtherQuantityType, OtherRep > const &other) noexcept
 Implicitly convert from a quantity with a different physical units type or representation type, scaling the value as appropriate.
 
constexpr quantity (Rep store_value) noexcept
 Construct a quantity holding the specified representation value.
 
template<typename OtherQuantityType, typename OtherRep = Rep, constraints< std::enable_if_t< quantity_detail::is_explicitly_convertible_v< QuantityType, OtherQuantityType > > > = nullptr>
constexpr auto as () const noexcept -> quantity< OtherQuantityType, OtherRep >
 Convert the stored quantity to the specified physical units type and representation.
 
template<typename OtherQuantityType, typename OtherRep = Rep, constraints< std::enable_if_t< quantity_detail::is_explicitly_convertible_v< QuantityType, OtherQuantityType > > > = nullptr>
constexpr auto count_of () const noexcept -> OtherRep
 Get the numeric representation of the stored quantity, for the specified physical units type.
 

Static Public Member Functions

static constexpr auto three_way_compare (quantity const &lhs, quantity const &rhs) noexcept -> strong_ordering
 three-way comparison between two quantities
 
template<typename OtherRep>
static constexpr auto three_way_compare (quantity const &lhs, quantity< QuantityType, OtherRep > const &rhs) noexcept -> strong_ordering
 three-way comparison between two quantities with the same physical units but different representations
 
template<typename OtherQuantityType, typename OtherRep, constraints< std::enable_if_t< quantity_detail::is_implicitly_convertible_v< OtherQuantityType, QuantityType > >, std::enable_if_t< quantity_detail::scaled_value_in_range_v< OtherQuantityType, OtherRep, QuantityType, std::common_type_t< Rep, OtherRep > > > > = nullptr>
static constexpr auto three_way_compare (quantity const &lhs, quantity< OtherQuantityType, OtherRep > const &rhs) noexcept -> strong_ordering
 three-way comparison between two quantities with different physical units
 
template<typename OtherQuantityType, typename OtherRep, constraints< std::enable_if_t< quantity_detail::is_implicitly_convertible_v< OtherQuantityType, QuantityType > >, std::enable_if_t<!quantity_detail::scaled_value_in_range_v< OtherQuantityType, OtherRep, QuantityType, std::common_type_t< Rep, OtherRep > > > > = nullptr>
static constexpr auto three_way_compare (quantity const &lhs, quantity< OtherQuantityType, OtherRep > const &rhs) noexcept -> strong_ordering
 three-way comparison between two quantities with different physical units where one quantity type is not within the scaled range of the other
 

Friends

template<typename Q = QuantityType, constraints< typename units_combination_traits< Q, Q >::sum_type > = nullptr>
constexpr auto operator+ (quantity const &lhs, quantity const &rhs) noexcept -> quantity< typename units_combination_traits< Q, Q >::sum_type, Rep >
 Add two quantities of the same type.
 
template<typename OtherQuantityType, typename OtherRep, typename Q = QuantityType, typename R = Rep, typename CommonRep = std::common_type_t<Rep, OtherRep>, constraints< typename units_combination_traits< QuantityType, OtherQuantityType >::ratio_type > = nullptr>
constexpr auto operator/ (quantity const &lhs, quantity< OtherQuantityType, OtherRep > const &rhs) noexcept -> quantity< typename units_combination_traits< QuantityType, OtherQuantityType >::ratio_type, CommonRep >
 Divide two quantities.
 
template<typename Scalar, typename Q = QuantityType, typename R = Rep, constraints< std::enable_if_t<!quantity_detail::is_quantity_v< Scalar > > > = nullptr, typename CommonRep = std::common_type_t<Rep, Scalar>, constraints< std::enable_if_t<!std::is_integral< CommonRep >::value > > = nullptr>
constexpr auto operator/ (quantity const &lhs, Scalar const &rhs) noexcept -> quantity< Q, CommonRep >
 Divide a quantity by a scalar.
 
template<typename OtherQuantityType, typename OtherRep, typename Q = QuantityType, typename R = Rep, typename CommonRep = std::common_type_t<Rep, OtherRep>, constraints< typename units_combination_traits< QuantityType, OtherQuantityType >::sum_type > = nullptr>
constexpr auto operator+ (quantity const &lhs, quantity< OtherQuantityType, OtherRep > const &rhs) noexcept -> quantity< typename units_combination_traits< QuantityType, OtherQuantityType >::sum_type, CommonRep >
 Add two quantities.
 
template<typename OtherQuantityType, typename OtherRep, typename Q = QuantityType, typename R = Rep, typename CommonRep = std::common_type_t<Rep, OtherRep>, constraints< typename units_combination_traits< QuantityType, OtherQuantityType >::difference_type > = nullptr>
constexpr auto operator- (quantity const &lhs, quantity< OtherQuantityType, OtherRep > const &rhs) noexcept -> quantity< typename units_combination_traits< QuantityType, OtherQuantityType >::difference_type, CommonRep >
 Subtract two quantities.
 
template<typename Scalar, typename Q = QuantityType, typename R = Rep, constraints< std::enable_if_t<!quantity_detail::is_quantity_v< Scalar > > > = nullptr, typename CommonRep = std::common_type_t<Rep, Scalar>>
constexpr auto operator* (quantity const &lhs, Scalar const &rhs) noexcept -> quantity< Q, CommonRep >
 Multiply a quantity by a scalar.
 
template<typename Scalar, typename Q = QuantityType, typename R = Rep, constraints< std::enable_if_t<!quantity_detail::is_quantity_v< Scalar > > > = nullptr, typename CommonRep = std::common_type_t<Rep, Scalar>>
constexpr auto operator* (Scalar const &lhs, quantity const &rhs) noexcept -> quantity< Q, CommonRep >
 Multiply a quantity by a scalar.
 
template<typename OtherQuantityType, typename OtherRep, typename Q = QuantityType, typename R = Rep, typename CommonRep = std::common_type_t<Rep, OtherRep>, constraints< typename units_combination_traits< QuantityType, OtherQuantityType >::product_type, std::enable_if_t<!std::is_integral< CommonRep >::value > > = nullptr>
constexpr auto operator* (quantity const &lhs, quantity< OtherQuantityType, OtherRep > const &rhs) noexcept -> quantity< typename units_combination_traits< QuantityType, OtherQuantityType >::product_type, CommonRep >
 Multiply two quantities.
 
template<typename OtherQuantityType, typename OtherRep, typename Q = QuantityType, typename R = Rep, typename CommonRep = std::common_type_t<Rep, OtherRep>, constraints< typename units_combination_traits< QuantityType, OtherQuantityType >::product_type, std::enable_if_t< std::is_integral< CommonRep >::value >, std::enable_if_t< std::is_signed< CommonRep >::value||(std::is_unsigned< R >::value &&std::is_unsigned< OtherRep >::value)>>
constexpr auto operator* (quantity const &lhs, quantity< OtherQuantityType, OtherRep > const &rhs) noexcept -> quantity< typename units_combination_traits< QuantityType, OtherQuantityType >::product_type, CommonRep >
 Multiply two quantities.
 
- Friends inherited from arene::base::generic_ordering_from_three_way_compare< quantity< QuantityType, Rep > >

Detailed Description

template<typename QuantityType, typename Rep>
class arene::base::quantity< QuantityType, Rep >

A class representing a quantity of a physical units type.

Conversions and arithmetic are supported if indicated by the appropriate traits for the physical units tag type. This allows the mathematical operations of engineering equations to be performed using instances of quantity, ensuring that the units of the result are correct, and preventing errors due to passing incorrect values or values in the wrong units.

Template Parameters
QuantityTypeA tag type representing the physical quantity
RepThe arithmetic type to use for holding the value

Constructor & Destructor Documentation

◆ quantity() [1/3]

template<typename QuantityType, typename Rep>
arene::base::quantity< QuantityType, Rep >::quantity ( )
inlineconstexprnoexcept

Default construct with a default-constructed representation value.

◆ quantity() [2/3]

template<typename QuantityType, typename Rep>
arene::base::quantity< QuantityType, Rep >::quantity ( Rep store_value)
inlineexplicitconstexprnoexcept

Construct a quantity holding the specified representation value.

Parameters
store_valueThe value to store

◆ quantity() [3/3]

template<typename QuantityType, typename Rep>
template<typename OtherQuantityType, typename OtherRep, constraints< std::enable_if_t< quantity_detail::is_implicitly_convertible_v< OtherQuantityType, QuantityType > >, std::enable_if_t< quantity_detail::scaled_value_in_range_v< OtherQuantityType, OtherRep, QuantityType, Rep > > > = nullptr>
arene::base::quantity< QuantityType, Rep >::quantity ( quantity< OtherQuantityType, OtherRep > const & other)
inlineconstexprnoexcept

Implicitly convert from a quantity with a different physical units type or representation type, scaling the value as appropriate.

Precondition
the physical unit types are marked as being implicitly convertible, and the scaled value is guaranteed to be in range, for integral representations.
Template Parameters
OtherQuantityTypeThe physical units type of the source quantity
OtherRepThe representation type of the source quantity
Parameters
otherThe other quantity

Member Function Documentation

◆ as()

template<typename QuantityType, typename Rep>
template<typename OtherQuantityType, typename OtherRep = Rep, constraints< std::enable_if_t< quantity_detail::is_explicitly_convertible_v< QuantityType, OtherQuantityType > > > = nullptr>
auto arene::base::quantity< QuantityType, Rep >::as ( ) const -> quantity<OtherQuantityType, OtherRep>
inlineconstexprnoexcept

Convert the stored quantity to the specified physical units type and representation.

The value is scaled as appropriate

Template Parameters
OtherQuantityTypeThe physical units type for which to retrieve the count
OtherRepThe representation type to return the count in; defaults to Rep
Returns
quantity<OtherQuantityType,OtherRep> holding the scaled value
Precondition
The physical units type QuantityType must be marked as explicitly convertible to OtherQuantityType

◆ count_of()

template<typename QuantityType, typename Rep>
template<typename OtherQuantityType, typename OtherRep = Rep, constraints< std::enable_if_t< quantity_detail::is_explicitly_convertible_v< QuantityType, OtherQuantityType > > > = nullptr>
auto arene::base::quantity< QuantityType, Rep >::count_of ( ) const -> OtherRep
inlineconstexprnoexcept

Get the numeric representation of the stored quantity, for the specified physical units type.

The value is scaled as appropriate

Template Parameters
OtherQuantityTypeThe physical units type for which to retrieve the count
OtherRepThe representation type to return the count in; defaults to Rep
Returns
OtherRep holding the scaled value
Precondition
The physical units type QuantityType must be marked as explicitly convertible to OtherQuantityType

◆ three_way_compare() [1/4]

template<typename QuantityType, typename Rep>
static constexpr auto arene::base::quantity< QuantityType, Rep >::three_way_compare ( quantity< QuantityType, Rep > const & lhs,
quantity< QuantityType, Rep > const & rhs ) -> strong_ordering
inlinestaticconstexprnoexcept

three-way comparison between two quantities

Parameters
lhsThe first object to compare
rhsThe second object to compare
Returns
strong_ordering strong_ordering::less if lhs is less than rhs, strong_ordering::equal if they hold the same value, and strong_ordering::greater if lhs is greater than rhs

◆ three_way_compare() [2/4]

template<typename QuantityType, typename Rep>
template<typename OtherQuantityType, typename OtherRep, constraints< std::enable_if_t< quantity_detail::is_implicitly_convertible_v< OtherQuantityType, QuantityType > >, std::enable_if_t< quantity_detail::scaled_value_in_range_v< OtherQuantityType, OtherRep, QuantityType, std::common_type_t< Rep, OtherRep > > > > = nullptr>
static constexpr auto arene::base::quantity< QuantityType, Rep >::three_way_compare ( quantity< QuantityType, Rep > const & lhs,
quantity< OtherQuantityType, OtherRep > const & rhs ) -> strong_ordering
inlinestaticconstexprnoexcept

three-way comparison between two quantities with different physical units

Parameters
lhsThe first object to compare
rhsThe second object to compare
Returns
strong_ordering strong_ordering::less if lhs is less than rhs, strong_ordering::equal if they hold the same value, and strong_ordering::greater if lhs is greater than rhs

◆ three_way_compare() [3/4]

template<typename QuantityType, typename Rep>
template<typename OtherQuantityType, typename OtherRep, constraints< std::enable_if_t< quantity_detail::is_implicitly_convertible_v< OtherQuantityType, QuantityType > >, std::enable_if_t<!quantity_detail::scaled_value_in_range_v< OtherQuantityType, OtherRep, QuantityType, std::common_type_t< Rep, OtherRep > > > > = nullptr>
static constexpr auto arene::base::quantity< QuantityType, Rep >::three_way_compare ( quantity< QuantityType, Rep > const & lhs,
quantity< OtherQuantityType, OtherRep > const & rhs ) -> strong_ordering
inlinestaticconstexprnoexcept

three-way comparison between two quantities with different physical units where one quantity type is not within the scaled range of the other

Parameters
lhsThe first object to compare
rhsThe second object to compare
Returns
strong_ordering strong_ordering::less if lhs is less than rhs, strong_ordering::equal if they hold the same value, and strong_ordering::greater if lhs is greater than rhs

◆ three_way_compare() [4/4]

template<typename QuantityType, typename Rep>
template<typename OtherRep>
static constexpr auto arene::base::quantity< QuantityType, Rep >::three_way_compare ( quantity< QuantityType, Rep > const & lhs,
quantity< QuantityType, OtherRep > const & rhs ) -> strong_ordering
inlinestaticconstexprnoexcept

three-way comparison between two quantities with the same physical units but different representations

Parameters
lhsThe first object to compare
rhsThe second object to compare
Returns
strong_ordering strong_ordering::less if lhs is less than rhs, strong_ordering::equal if they hold the same value, and strong_ordering::greater if lhs is greater than rhs

Friends And Related Symbol Documentation

◆ operator* [1/4]

template<typename QuantityType, typename Rep>
template<typename OtherQuantityType, typename OtherRep, typename Q = QuantityType, typename R = Rep, typename CommonRep = std::common_type_t<Rep, OtherRep>, constraints< typename units_combination_traits< QuantityType, OtherQuantityType >::product_type, std::enable_if_t<!std::is_integral< CommonRep >::value > > = nullptr>
auto operator* ( quantity< QuantityType, Rep > const & lhs,
quantity< OtherQuantityType, OtherRep > const & rhs ) -> quantity<typename units_combination_traits<QuantityType, OtherQuantityType>::product_type, CommonRep>
friend

Multiply two quantities.

Template Parameters
OtherQuantityTypeThe physical units type of the other quantity
OtherRepThe representation type of the other quantity
QTemplate parameter introduced to provide constraints; equivalent to QuantityType
RTemplate parameter introduced to provide constraints; equivalent to Rep
CommonRepTemplate parameter introduced to provide constraints; the common representation type of Rep and OtherRep
Parameters
lhsThe left hand operand
rhsThe right hand operand
Returns
quantity<product_type,CommonRep> A quantity with the physical units type specified as the product_type for QuantityType and OtherQuantityType, and a representation which is the common type of Rep and OtherRep, holding the product of the two quantity values
Precondition
There is a product_type specified in units_combination_traits<QuantityType,OtherQuantityType>

◆ operator* [2/4]

template<typename QuantityType, typename Rep>
template<typename OtherQuantityType, typename OtherRep, typename Q = QuantityType, typename R = Rep, typename CommonRep = std::common_type_t<Rep, OtherRep>, constraints< typename units_combination_traits< QuantityType, OtherQuantityType >::product_type, std::enable_if_t< std::is_integral< CommonRep >::value >, std::enable_if_t< std::is_signed< CommonRep >::value||(std::is_unsigned< R >::value &&std::is_unsigned< OtherRep >::value)>>
auto operator* ( quantity< QuantityType, Rep > const & lhs,
quantity< OtherQuantityType, OtherRep > const & rhs ) -> quantity<typename units_combination_traits<QuantityType, OtherQuantityType>::product_type, CommonRep>
friend

Multiply two quantities.

Template Parameters
OtherQuantityTypeThe physical units type of the other quantity
OtherRepThe representation type of the other quantity
QTemplate parameter introduced to provide constraints; equivalent to QuantityType
RTemplate parameter introduced to provide constraints; equivalent to Rep
CommonRepTemplate parameter introduced to provide constraints; the common representation type of Rep and OtherRep
Parameters
lhsThe left hand operand
rhsThe right hand operand
Returns
quantity<product_type,CommonRep> A quantity with the physical units type specified as the product_type for QuantityType and OtherQuantityType, and a representation which is the common type of Rep and OtherRep, holding the left hand quantity value multiplied by the right hand quantity value
Precondition
There is a product_type specified in units_combination_traits<QuantityType,OtherQuantityType>

◆ operator* [3/4]

template<typename QuantityType, typename Rep>
template<typename Scalar, typename Q = QuantityType, typename R = Rep, constraints< std::enable_if_t<!quantity_detail::is_quantity_v< Scalar > > > = nullptr, typename CommonRep = std::common_type_t<Rep, Scalar>>
auto operator* ( quantity< QuantityType, Rep > const & lhs,
Scalar const & rhs ) -> quantity<Q, CommonRep>
friend

Multiply a quantity by a scalar.

Template Parameters
ScalarThe type of the scalar
QTemplate parameter introduced to provide constraints; equivalent to QuantityType
RTemplate parameter introduced to provide constraints; equivalent to Rep
CommonRepTemplate parameter introduced to provide constraints; the common representation type of Rep and Scalar
Parameters
lhsThe left hand operand
rhsThe right hand operand
Returns
quantity<Q,CommonRep> A quantity with the same physical units type, and a representation which is the common type of Rep and Scalar, holding the product of the quantity value and the scalar value

◆ operator* [4/4]

template<typename QuantityType, typename Rep>
template<typename Scalar, typename Q = QuantityType, typename R = Rep, constraints< std::enable_if_t<!quantity_detail::is_quantity_v< Scalar > > > = nullptr, typename CommonRep = std::common_type_t<Rep, Scalar>>
auto operator* ( Scalar const & lhs,
quantity< QuantityType, Rep > const & rhs ) -> quantity<Q, CommonRep>
friend

Multiply a quantity by a scalar.

Template Parameters
ScalarThe type of the scalar
QTemplate parameter introduced to provide constraints; equivalent to QuantityType
RTemplate parameter introduced to provide constraints; equivalent to Rep
CommonRepTemplate parameter introduced to provide constraints; the common representation type of Rep and Scalar
Parameters
lhsThe left hand operand
rhsThe right hand operand
Returns
quantity<Q,CommonRep> A quantity with the same physical units type, and a representation which is the common type of Rep and Scalar, holding the quantity value multiplied by the scalar value

◆ operator+ [1/2]

template<typename QuantityType, typename Rep>
template<typename Q = QuantityType, constraints< typename units_combination_traits< Q, Q >::sum_type > = nullptr>
auto operator+ ( quantity< QuantityType, Rep > const & lhs,
quantity< QuantityType, Rep > const & rhs ) -> quantity<typename units_combination_traits<Q, Q>::sum_type, Rep>
friend

Add two quantities of the same type.

Template Parameters
QTemplate parameter introduced to provide constraints; equivalent to QuantityType
Parameters
lhsThe first quantity
rhsThe second quantity
Returns
quantity<sum_type,Rep> A quantity with the physical units type specified as the sum_type for QuantityType and QuantityType, and a representation of Rep, holding the sum of the two quantity values

◆ operator+ [2/2]

template<typename QuantityType, typename Rep>
template<typename OtherQuantityType, typename OtherRep, typename Q = QuantityType, typename R = Rep, typename CommonRep = std::common_type_t<Rep, OtherRep>, constraints< typename units_combination_traits< QuantityType, OtherQuantityType >::sum_type > = nullptr>
auto operator+ ( quantity< QuantityType, Rep > const & lhs,
quantity< OtherQuantityType, OtherRep > const & rhs ) -> quantity<typename units_combination_traits<QuantityType, OtherQuantityType>::sum_type, CommonRep>
friend

Add two quantities.

Template Parameters
OtherQuantityTypeThe physical units type of the other quantity
OtherRepThe representation type of the other quantity
QTemplate parameter introduced to provide constraints; equivalent to QuantityType
RTemplate parameter introduced to provide constraints; equivalent to Rep
Parameters
lhsThe first quantity
rhsThe second quantity
Returns
quantity<sum_type,CommonRep> A quantity with the physical units type specified as the sum_type for QuantityType and OtherQuantityType, and a representation which is the common type of Rep and OtherRep, holding the sum of the two quantity values

◆ operator-

template<typename QuantityType, typename Rep>
template<typename OtherQuantityType, typename OtherRep, typename Q = QuantityType, typename R = Rep, typename CommonRep = std::common_type_t<Rep, OtherRep>, constraints< typename units_combination_traits< QuantityType, OtherQuantityType >::difference_type > = nullptr>
auto operator- ( quantity< QuantityType, Rep > const & lhs,
quantity< OtherQuantityType, OtherRep > const & rhs ) -> quantity<typename units_combination_traits<QuantityType, OtherQuantityType>::difference_type, CommonRep>
friend

Subtract two quantities.

Template Parameters
OtherQuantityTypeThe physical units type of the other quantity
OtherRepThe representation type of the other quantity
QTemplate parameter introduced to provide constraints; equivalent to QuantityType
RTemplate parameter introduced to provide constraints; equivalent to Rep
Parameters
lhsThe first quantity
rhsThe second quantity
Returns
quantity<difference_type,CommonRep> A quantity with the physical units type specified as the difference_type for QuantityType and OtherQuantityType, and a representation which is the common type of Rep and OtherRep, holding the difference of the two quantity values

◆ operator/ [1/2]

template<typename QuantityType, typename Rep>
template<typename OtherQuantityType, typename OtherRep, typename Q = QuantityType, typename R = Rep, typename CommonRep = std::common_type_t<Rep, OtherRep>, constraints< typename units_combination_traits< QuantityType, OtherQuantityType >::ratio_type > = nullptr>
auto operator/ ( quantity< QuantityType, Rep > const & lhs,
quantity< OtherQuantityType, OtherRep > const & rhs ) -> quantity<typename units_combination_traits<QuantityType, OtherQuantityType>::ratio_type, CommonRep>
friend

Divide two quantities.

Template Parameters
OtherQuantityTypeThe physical units type of the other quantity
OtherRepThe representation type of the other quantity
QTemplate parameter introduced to provide constraints; equivalent to QuantityType
RTemplate parameter introduced to provide constraints; equivalent to Rep
CommonRepTemplate parameter introduced to provide constraints; the common representation type of Rep and OtherRep
Parameters
lhsThe left hand operand
rhsThe right hand operand
Returns
quantity<ratio_type,CommonRep> A quantity with the physical units type specified as the ratio_type for QuantityType and OtherQuantityType, and a representation which is the common type of Rep and OtherRep, holding the left hand quantity value divided by the right hand quantity value
Precondition
There is a ratio_type specified in units_combination_traits<QuantityType,OtherQuantityType>

◆ operator/ [2/2]

template<typename QuantityType, typename Rep>
template<typename Scalar, typename Q = QuantityType, typename R = Rep, constraints< std::enable_if_t<!quantity_detail::is_quantity_v< Scalar > > > = nullptr, typename CommonRep = std::common_type_t<Rep, Scalar>, constraints< std::enable_if_t<!std::is_integral< CommonRep >::value > > = nullptr>
auto operator/ ( quantity< QuantityType, Rep > const & lhs,
Scalar const & rhs ) -> quantity<Q, CommonRep>
friend

Divide a quantity by a scalar.

Template Parameters
ScalarThe type of the scalar
QTemplate parameter introduced to provide constraints; equivalent to QuantityType
RTemplate parameter introduced to provide constraints; equivalent to Rep
CommonRepTemplate parameter introduced to provide constraints; the common representation type of Rep and Scalar
Parameters
lhsThe left hand operand
rhsThe right hand operand
Returns
quantity<Q,CommonRep> A quantity with the same physical units type, and a representation which is the common type of Rep and Scalar, holding the quantity value divided by the scalar value

The documentation for this class was generated from the following file: