Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Phyth::Quantity< UnitT > Struct Template Reference

Physical quantity with a value and a compile-time unit. More...

#include <Quantity.hpp>

Public Member Functions

constexpr Quantity (const double v=0.0)
 Construct a quantity with a given value (default: 0)
 
template<typename OtherUnit >
constexpr Quantity (Quantity< OtherUnit > other)
 Convert from another unit of the same dimension.
 
template<typename TargetUnit >
constexpr auto As () const
 Convert this quantity to a different unit of the same dimension.
 
template<typename TargetType >
constexpr auto To () const
 Extract the numeric value as a different type.
 
template<typename OtherUnit >
constexpr Quantity & operator+= (Quantity< OtherUnit > other)
 Add another quantity of the same dimension.
 
template<typename OtherUnit >
constexpr Quantity & operator-= (Quantity< OtherUnit > other)
 Subtract another quantity of the same dimension.
 
constexpr Quantity & operator*= (const double scalar)
 Multiply the value by a scalar.
 
constexpr Quantity & operator/= (const double scalar)
 Divide the value by a scalar.
 
constexpr Quantity & operator++ ()
 Pre-increment: increase value by 1.
 
constexpr Quantity & operator-- ()
 Pre-decrement: decrease value by 1.
 
constexpr Quantity operator++ (int)
 Post-increment: increase value by 1, return old value.
 
constexpr Quantity operator-- (int)
 Post-decrement: decrease value by 1, return old value.
 

Public Attributes

double value
 

Detailed Description

template<typename UnitT>
struct Phyth::Quantity< UnitT >

Physical quantity with a value and a compile-time unit.

Quantity is the primary user-facing type. It stores a numeric value and carries a unit type that encodes both dimension (SI exponents) and scale (e.g., meter vs. kilometer).

Template Parameters
UnitTA unit type (e.g., Unit<Length, std::ratio<1>>)

Example: Quantity<Meter> length = 5.0_m; Quantity<Second> time = 3.0_s; auto speed = length / time; // Quantity<Velocity> with value ~1.666...

Definition at line 27 of file Quantity.hpp.

Constructor & Destructor Documentation

◆ Quantity() [1/2]

template<typename UnitT >
constexpr Phyth::Quantity< UnitT >::Quantity ( const double  v = 0.0)
inlineconstexpr

Construct a quantity with a given value (default: 0)

Definition at line 34 of file Quantity.hpp.

◆ Quantity() [2/2]

template<typename UnitT >
template<typename OtherUnit >
constexpr Phyth::Quantity< UnitT >::Quantity ( Quantity< OtherUnit >  other)
inlineconstexpr

Convert from another unit of the same dimension.

The stored value is converted to this unit's scale.

Template Parameters
OtherUnitThe source unit type
Parameters
otherThe quantity to convert from

Definition at line 46 of file Quantity.hpp.

Member Function Documentation

◆ As()

template<typename UnitT >
template<typename TargetUnit >
constexpr auto Phyth::Quantity< UnitT >::As ( ) const
inlineconstexpr

Convert this quantity to a different unit of the same dimension.

Template Parameters
TargetUnitThe target unit type
Returns
Quantity<TargetUnit> with the same physical value

Example: auto length = 1.0_km; auto in_meters = length.as<Meter>(); // 1000 m

Definition at line 63 of file Quantity.hpp.

◆ operator*=()

template<typename UnitT >
constexpr Quantity & Phyth::Quantity< UnitT >::operator*= ( const double  scalar)
inlineconstexpr

Multiply the value by a scalar.

Definition at line 112 of file Quantity.hpp.

◆ operator++() [1/2]

template<typename UnitT >
constexpr Quantity & Phyth::Quantity< UnitT >::operator++ ( )
inlineconstexpr

Pre-increment: increase value by 1.

Definition at line 124 of file Quantity.hpp.

◆ operator++() [2/2]

template<typename UnitT >
constexpr Quantity Phyth::Quantity< UnitT >::operator++ ( int  )
inlineconstexpr

Post-increment: increase value by 1, return old value.

Definition at line 136 of file Quantity.hpp.

◆ operator+=()

template<typename UnitT >
template<typename OtherUnit >
constexpr Quantity & Phyth::Quantity< UnitT >::operator+= ( Quantity< OtherUnit >  other)
inlineconstexpr

Add another quantity of the same dimension.

Template Parameters
OtherUnitThe other quantity's unit type
Parameters
otherThe quantity to add
Returns
Reference to this quantity

Definition at line 89 of file Quantity.hpp.

◆ operator--() [1/2]

template<typename UnitT >
constexpr Quantity & Phyth::Quantity< UnitT >::operator-- ( )
inlineconstexpr

Pre-decrement: decrease value by 1.

Definition at line 130 of file Quantity.hpp.

◆ operator--() [2/2]

template<typename UnitT >
constexpr Quantity Phyth::Quantity< UnitT >::operator-- ( int  )
inlineconstexpr

Post-decrement: decrease value by 1, return old value.

Definition at line 143 of file Quantity.hpp.

◆ operator-=()

template<typename UnitT >
template<typename OtherUnit >
constexpr Quantity & Phyth::Quantity< UnitT >::operator-= ( Quantity< OtherUnit >  other)
inlineconstexpr

Subtract another quantity of the same dimension.

Template Parameters
OtherUnitThe other quantity's unit type
Parameters
otherThe quantity to subtract
Returns
Reference to this quantity

Definition at line 104 of file Quantity.hpp.

◆ operator/=()

template<typename UnitT >
constexpr Quantity & Phyth::Quantity< UnitT >::operator/= ( const double  scalar)
inlineconstexpr

Divide the value by a scalar.

Definition at line 118 of file Quantity.hpp.

◆ To()

template<typename UnitT >
template<typename TargetType >
constexpr auto Phyth::Quantity< UnitT >::To ( ) const
inlineconstexpr

Extract the numeric value as a different type.

Template Parameters
TargetTypeThe numeric type to convert to (e.g., float, int)
Returns
The value cast to TargetType

Definition at line 77 of file Quantity.hpp.

Member Data Documentation

◆ value

template<typename UnitT >
double Phyth::Quantity< UnitT >::value

The numeric value of this quantity, stored in the unit's base scale

Definition at line 31 of file Quantity.hpp.


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