MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
Units Utilities for tracking, documenting, and enforcing units

Namespaces

namespace  mtcore::units::dimensions
 Represents prebuilt dimensions for units.
 

Concepts

concept  mtcore::units::IsUnit
 Concept to check that a type is a unit.
 

Classes

struct  mtcore::units::UnitValue< Underlying, Units >
 Represents a value with associated units. More...
 
struct  mtcore::units::Unit< UnitCategory, S, PiPow, Tr, exp >
 Represents a single unit of measurement. More...
 
struct  mtcore::units::Units< Us >
 List of units. More...
 
struct  mtcore::units::UnitValue< Underlying, Units<> >
 Specialization where units list is empty (basically a "unitless" value) Can be directly cast to a numeric type. More...
 
struct  mtcore::units::UnitValue< Underlying, Units< U1, UnitsSub... > >
 Represents a unit value with a specific, non-empty unit list. More...
 

Functions

template<std::floating_point Val, typename... Dims>
constexpr UnitValue< Val, Units< Dims... > > mtcore::units::operator* (Val lhs, const Units< Dims... > &)
 Multiply a number with units to get a unit value.
 
template<typename... Dims1, typename... Dims2>
constexpr auto mtcore::units::operator* (const Units< Dims1... > &, const Units< Dims2... > &)
 Multiply units to combine them.
 
template<typename... Dims1, typename... Dims2>
constexpr auto mtcore::units::operator/ (const Units< Dims1... > &, const Units< Dims2... > &)
 Divide units to combine them.
 
template<std::floating_point Val, typename... Dims>
constexpr auto mtcore::units::operator/ (Val lhs, const Units< Dims... > &)
 Divide units with a number to get a unit value.
 
template<typename U1, typename Us1, typename U2, typename Us2>
constexpr auto mtcore::units::operator* (const UnitValue< U1, Us1 > &lhs, const UnitValue< U2, Us2 > &rhs)
 Multiply unit values together.
 
template<typename U1, typename Us1, typename U2, typename Us2>
constexpr auto mtcore::units::operator/ (const UnitValue< U1, Us1 > &lhs, const UnitValue< U2, Us2 > &rhs)
 Divide unit values.
 
template<std::floating_point I, typename U, typename Us>
constexpr auto mtcore::units::operator/ (I value, UnitValue< U, Us > lhs)
 Divide a number with a unit value.
 
template<std::floating_point I, typename U, typename Us>
constexpr auto mtcore::units::operator/ (UnitValue< U, Us > lhs, I value)
 Divide a unit value with a number.
 
template<std::integral I, typename U, typename Us>
constexpr auto mtcore::units::operator/ (I value, const UnitValue< U, Us > &lhs)
 Divide a number with a unit value.
 
template<std::floating_point Val, typename U, typename Us>
constexpr UnitValue< U, Us > mtcore::units::operator* (const UnitValue< U, Us > &lhs, Val rhs)
 Multiply a unit value with a number.
 
template<std::floating_point Val, typename U, typename Us>
constexpr UnitValue< Val, Us > mtcore::units::operator* (Val lhs, const UnitValue< U, Us > &rhs)
 Multiply a unit value with a number.
 
template<typename U, typename Us, typename... Dims>
constexpr auto mtcore::units::operator* (UnitValue< U, Us > lhs, const Units< Dims... > &u)
 Multiply a unit value with units to combine them.
 
template<typename U, typename Us, typename... Dims>
constexpr auto mtcore::units::operator/ (UnitValue< U, Us > lhs, const Units< Dims... > &u)
 Divide a unit value with units to combine them.
 

Detailed Description

Function Documentation

◆ operator*() [1/6]

template<typename... Dims1, typename... Dims2>
auto mtcore::units::operator* ( const Units< Dims1... > & ,
const Units< Dims2... > &  )
constexpr

Multiply units to combine them.

Definition at line 740 of file units/base.hpp.

740 {
741 return typename impl::WithoutZeroExponents<typename impl::ConcatUnits<Units<Dims1...>, Units<Dims2...>>::T>::T{};
742 }
List of units.

◆ operator*() [2/6]

template<std::floating_point Val, typename U, typename Us>
UnitValue< U, Us > mtcore::units::operator* ( const UnitValue< U, Us > & lhs,
Val rhs )
constexpr

Multiply a unit value with a number.

Definition at line 819 of file units/base.hpp.

819 {
820 return {static_cast<U>(lhs) * rhs.val};
821 }

◆ operator*() [3/6]

template<typename U1, typename Us1, typename U2, typename Us2>
auto mtcore::units::operator* ( const UnitValue< U1, Us1 > & lhs,
const UnitValue< U2, Us2 > & rhs )
constexpr

Multiply unit values together.

Definition at line 770 of file units/base.hpp.

770 {
771 using RetUnits = typename impl::ConcatUnits<std::remove_const_t<typename UnitValue<U1, Us1>::UnitsType>,
772 std::remove_const_t<typename UnitValue<U2, Us2>::UnitsType>>::T;
773 const auto r = lhs.val * rhs.val;
774 return UnitValue<std::remove_cvref_t<decltype(r)>, RetUnits>{r};
775 }
Represents a value with associated units.

◆ operator*() [4/6]

template<typename U, typename Us, typename... Dims>
auto mtcore::units::operator* ( UnitValue< U, Us > lhs,
const Units< Dims... > & u )
constexpr

Multiply a unit value with units to combine them.

Definition at line 843 of file units/base.hpp.

843 {
844 using RetUnits = std::remove_const_t<decltype(std::declval<typename UnitValue<U, Us>::UnitsType>() * u)>;
845 return UnitValue<U, RetUnits>{lhs.val};
846 }

◆ operator*() [5/6]

template<std::floating_point Val, typename... Dims>
UnitValue< Val, Units< Dims... > > mtcore::units::operator* ( Val lhs,
const Units< Dims... > &  )
constexpr

Multiply a number with units to get a unit value.

Definition at line 728 of file units/base.hpp.

728 {
729 return {lhs};
730 }

◆ operator*() [6/6]

template<std::floating_point Val, typename U, typename Us>
UnitValue< Val, Us > mtcore::units::operator* ( Val lhs,
const UnitValue< U, Us > & rhs )
constexpr

Multiply a unit value with a number.

Definition at line 825 of file units/base.hpp.

825 {
826 return {lhs * static_cast<Val>(rhs.val)};
827 }

◆ operator/() [1/7]

template<typename... Dims1, typename... Dims2>
auto mtcore::units::operator/ ( const Units< Dims1... > & ,
const Units< Dims2... > &  )
constexpr

Divide units to combine them.

Definition at line 749 of file units/base.hpp.

749 {
750 return typename impl::WithoutZeroExponents<
751 typename impl::ConcatUnits<Units<Dims1...>, Units<typename impl::FlipUnit<Dims2>::T...>>::T>::T{};
752 }

◆ operator/() [2/7]

template<typename U1, typename Us1, typename U2, typename Us2>
auto mtcore::units::operator/ ( const UnitValue< U1, Us1 > & lhs,
const UnitValue< U2, Us2 > & rhs )
constexpr

Divide unit values.

Definition at line 779 of file units/base.hpp.

779 {
780 using RetUnits = typename impl::ConcatUnits<std::remove_const_t<typename UnitValue<U1, Us1>::UnitsType>,
781 std::remove_const_t<typename UnitValue<U2, Us2>::UnitsType>>::T;
782 const auto r = lhs.val * rhs.val;
783 if constexpr (std::is_same_v<Units<>, RetUnits>) {
784 return r;
785 }
786 return UnitValue<std::remove_cvref_t<decltype(r)>, RetUnits>{r};
787 }

◆ operator/() [3/7]

template<std::integral I, typename U, typename Us>
auto mtcore::units::operator/ ( I value,
const UnitValue< U, Us > & lhs )
constexpr

Divide a number with a unit value.

Definition at line 805 of file units/base.hpp.

805 {
806 using RetUnits = typename std::remove_const_t<decltype(1 / std::declval<Us>())>::UnitsType;
807 return UnitValue<U, RetUnits>{static_cast<U>(value) / lhs.val};
808 }

◆ operator/() [4/7]

template<std::floating_point I, typename U, typename Us>
auto mtcore::units::operator/ ( I value,
UnitValue< U, Us > lhs )
constexpr

Divide a number with a unit value.

Definition at line 791 of file units/base.hpp.

791 {
792 using RetUnits = typename std::remove_const_t<decltype(1 / std::declval<Us>())>::UnitsType;
793 return UnitValue<U, RetUnits>{static_cast<U>(value) / lhs.val};
794 }

◆ operator/() [5/7]

template<typename U, typename Us, typename... Dims>
auto mtcore::units::operator/ ( UnitValue< U, Us > lhs,
const Units< Dims... > & u )
constexpr

Divide a unit value with units to combine them.

Definition at line 850 of file units/base.hpp.

850 {
851 using RetUnits = std::remove_const_t<decltype(std::declval<typename UnitValue<U, Us>::UnitsType>() / u)>;
852 return UnitValue<U, RetUnits>{lhs.val};
853 }

◆ operator/() [6/7]

template<std::floating_point I, typename U, typename Us>
auto mtcore::units::operator/ ( UnitValue< U, Us > lhs,
I value )
constexpr

Divide a unit value with a number.

Definition at line 798 of file units/base.hpp.

798 {
799 using RetUnits = std::remove_const_t<Us>;
800 return UnitValue<U, RetUnits>{lhs.val / static_cast<U>(value)};
801 }

◆ operator/() [7/7]

template<std::floating_point Val, typename... Dims>
auto mtcore::units::operator/ ( Val lhs,
const Units< Dims... > &  )
constexpr

Divide units with a number to get a unit value.

Definition at line 756 of file units/base.hpp.

756 {
757 return UnitValue<Val, typename impl::WithoutZeroExponents<Units<typename impl::FlipUnit<Dims...>::T>>::T>{lhs};
758 }