All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
util::quantities::concepts::Quantity< Unit, T > Struct Template Reference

A value measured in the specified unit. More...

#include <quantities.h>

Public Types

using value_t = T
 Type of the stored value. More...
 
using unit_t = Unit
 The unit and scale of this quantity. More...
 
using quantity_t = Quantity< Unit, T >
 The type of this class. More...
 
using baseunit_t = typename unit_t::baseunit_t
 Description of the unscaled unit. More...
 

Public Member Functions

 Quantity ()=default
 Constructor: value is left uninitialized. More...
 
constexpr Quantity (value_t v)
 Constructor: takes a value in the intended representation. More...
 
template<typename Q , typename std::enable_if_t< details::is_quantity_v< Q >> * = nullptr>
constexpr Quantity (Q q)
 Constructor: converts from another quantity. More...
 
constexpr value_t value () const
 Returns the value of the quantity. More...
 
constexpr operator value_t () const
 Explicit conversion to the base quantity. More...
 
template<typename OQ >
constexpr OQ convertInto () const
 Convert this quantity into the specified one. More...
 
template<typename OU , typename OT >
constexpr auto operator+ (Quantity< OU, OT > const other) const -> quantity_t
 
template<typename OU , typename OT >
constexpr auto operator- (Quantity< OU, OT > const other) const -> quantity_t
 
template<typename OU , typename OT >
constexpr auto plus (Quantity< OU, OT > const other) const -> quantity_t
 
template<typename OU , typename OT >
constexpr auto minus (Quantity< OU, OT > const other) const -> quantity_t
 
template<typename OU , typename OT >
constexpr auto operator/ (Quantity< OU, OT > const q) const -> value_t
 
template<typename OU , typename OT >
auto operator+= (Quantity< OU, OT > const other) -> quantity_t &
 
template<typename OU , typename OT >
auto operator-= (Quantity< OU, OT > const other) -> quantity_t &
 
Asymmetric operand arithmetic operations

These arithmetic operations take care of preserving the quantity through them. Not all possible (or reasonable) operations are supported yet. Some operations that may be symmetric (like multiplication by a scalar) are implemented as free functions rather than methods.

Note
These operations are essentially provided by convenience. There are many cases (corner and not) where the implicit conversion to the base type kicks in. This implementation does not aim to prevent that from happening, but requests are welcome to add features to allow that not to happen, with some care of the user.
Operators + and - support only quantity operands of the same type, and no plain number operand. The rational behind this is that when writing a + b with a and b two homogeneous quantities, we expect to be able to use b + a as well. But it a and b are different types (e.g. one is second, the other is millisecond), an arbitrary choice has to be made on which type the result should be, and having different types for a + b and b + a is not acceptable. If the intention is clear, methods plus() and minus() are provided with the understanding that e.g. a.plus(b) explicitly requires the result to be of type a.
template<typename OU , typename OT >
constexpr quantity_t operator+ (Quantity< OU, OT > const other) const
 Returns a quantity sum of this and other (must have same unit). More...
 
template<typename OU , typename OT >
constexpr quantity_t operator- (Quantity< OU, OT > const other) const
 
template<typename OU , typename OT >
constexpr quantity_t plus (Quantity< OU, OT > const other) const
 Returns a quantity sum of this and other. More...
 
template<typename OU , typename OT >
constexpr quantity_t minus (Quantity< OU, OT > const other) const
 Returns a quantity difference of this and other. More...
 
template<typename OU , typename OT >
constexpr value_t operator/ (Quantity< OU, OT > q) const
 Division by a quantity, returns a pure number. More...
 
template<typename OU , typename OT >
quantity_toperator+= (Quantity< OU, OT > const other)
 Add the other quantity (possibly concerted) to this one. More...
 
template<typename OU , typename OT >
quantity_toperator-= (Quantity< OU, OT > const other)
 Subtract the other quantity (possibly concerted) to this one. More...
 
template<typename OT >
std::enable_if_t
< std::is_arithmetic_v< OT >
, quantity_t & > 
operator*= (OT factor)
 Scale this quantity by a factor. More...
 
template<typename OT >
std::enable_if_t
< std::is_arithmetic_v< OT >
, quantity_t & > 
operator/= (OT quot)
 Scale the quantity dividing it by a quotient. More...
 
constexpr quantity_t operator+ () const
 Returns a quantity with same value. More...
 
constexpr quantity_t operator- () const
 Returns a quantity with same value but the sign flipped. More...
 
constexpr quantity_t abs () const
 Returns a quantity with the absolute value of this one. More...
 
Comparisons.

Comparisons with plain numbers are managed by implicit conversion. More care is needed for quantities. Comparisons between two quantity instances a and b work this way:

  • if a and b do not have the same unit, they are not comparable
  • if a and b have the same unit, one is converted to the other and the comparison is performed there
  • if a and b have the same scaled unit, their values are compared directly

Value storage types are compared according to C++ rules.

template<typename OU , typename OT >
constexpr bool operator== (Quantity< OU, OT > const other) const
 
template<typename OU , typename OT >
constexpr bool operator!= (Quantity< OU, OT > const other) const
 
template<typename OU , typename OT >
constexpr bool operator>= (Quantity< OU, OT > const other) const
 
template<typename OU , typename OT >
constexpr bool operator> (Quantity< OU, OT > const other) const
 
template<typename OU , typename OT >
constexpr bool operator<= (Quantity< OU, OT > const other) const
 
template<typename OU , typename OT >
constexpr bool operator< (Quantity< OU, OT > const other) const
 

Static Public Member Functions

template<typename U >
static constexpr quantity_t castFrom (U value)
 Returns a new quantity initialized with the specified value. More...
 

Private Attributes

value_t fValue {}
 Stored value. More...
 

Access to the scaled unit.

template<typename U >
static constexpr bool is_compatible_value_v = details::is_value_compatible_with_v<U, value_t>
 Whether U is a value type compatible with value_t. More...
 
template<typename U >
static constexpr bool has_compatible_value_v = details::has_value_compatible_with_v<U, value_t>
 Whether U has (or is) a value type compatible with value_t. More...
 
static constexpr unit_t unit ()
 Returns an object with as type the scaled unit (unit_t). More...
 
static constexpr baseunit_t baseUnit ()
 Returns an object with as type the base unit (baseunit_t). More...
 
static auto unitName ()
 Returns the full name of the unit, in a string-like object. More...
 
static auto unitSymbol ()
 Returns the symbol of the unit, in a string-like object. More...
 
template<typename OU >
static constexpr bool sameBaseUnitAs ()
 Returns whether this quantity has the same base unit as OU. More...
 
template<typename OU >
static constexpr bool sameUnitAs ()
 Returns whether this quantity has same unit and scale as OU. More...
 
template<typename U >
static constexpr bool isCompatibleValue ()
 Returns whether U is a value type compatible with value_t. More...
 
template<typename U >
static constexpr bool hasCompatibleValue ()
 

Detailed Description

template<typename Unit, typename T = double>
struct util::quantities::concepts::Quantity< Unit, T >

A value measured in the specified unit.


Template Parameters
Unitthe scaled unit type representing the unit of this quantity
Ttype of base value

A Quantity instance is a glorified number of type T (or, value_t). The Quantity class adds to it the explicit documentation of the unit the value is measured in, plus some attempt to preserve that information:

(milliampere and microampere are hypotetical instantiations of Quantity template class from util::quantities, and they also have a literal conversion to correctly interpret things like 2.0_ma or 7_A)

Implementation details

Definition at line 566 of file quantities.h.

Member Typedef Documentation

template<typename Unit, typename T = double>
using util::quantities::concepts::Quantity< Unit, T >::baseunit_t = typename unit_t::baseunit_t

Description of the unscaled unit.

Definition at line 575 of file quantities.h.

template<typename Unit, typename T = double>
using util::quantities::concepts::Quantity< Unit, T >::quantity_t = Quantity<Unit, T>

The type of this class.

Definition at line 572 of file quantities.h.

template<typename Unit, typename T = double>
using util::quantities::concepts::Quantity< Unit, T >::unit_t = Unit

The unit and scale of this quantity.

Definition at line 571 of file quantities.h.

template<typename Unit, typename T = double>
using util::quantities::concepts::Quantity< Unit, T >::value_t = T

Type of the stored value.

Definition at line 570 of file quantities.h.

Constructor & Destructor Documentation

template<typename Unit, typename T = double>
util::quantities::concepts::Quantity< Unit, T >::Quantity ( )
explicitdefault

Constructor: value is left uninitialized.

template<typename Unit, typename T = double>
constexpr util::quantities::concepts::Quantity< Unit, T >::Quantity ( value_t  v)
inlineexplicit

Constructor: takes a value in the intended representation.

Definition at line 584 of file quantities.h.

584 : fValue(v) {}
value_t fValue
Stored value.
Definition: quantities.h:830
template<typename Unit, typename T = double>
template<typename Q , typename std::enable_if_t< details::is_quantity_v< Q >> * = nullptr>
constexpr util::quantities::concepts::Quantity< Unit, T >::Quantity ( q)
inline

Constructor: converts from another quantity.

Template Parameters
Qtype of the other quantity
Parameters
qquantity to be converted from

Quantities are required to be in the same unit (unit scale may differ). The value in q is converted from its native scale into the one of this quantity.

Definition at line 599 of file quantities.h.

600  : fValue
601  {unit_t::template fromRepr<typename Q::unit_t::ratio>(q.value()) }
602  {
603  static_assert(sameBaseUnitAs<Q>(),
604  "Can't construct from quantity with different base unit"
605  );
606  }
value_t fValue
Stored value.
Definition: quantities.h:830

Member Function Documentation

template<typename Unit, typename T = double>
constexpr quantity_t util::quantities::concepts::Quantity< Unit, T >::abs ( ) const
inline

Returns a quantity with the absolute value of this one.

Definition at line 693 of file quantities.h.

694  { return quantity_t(util::abs(value())); }
constexpr auto abs(T v)
Returns the absolute value of the argument.
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename Unit, typename T = double>
static constexpr baseunit_t util::quantities::concepts::Quantity< Unit, T >::baseUnit ( )
inlinestatic

Returns an object with as type the base unit (baseunit_t).

Definition at line 748 of file quantities.h.

748 { return {}; }
template<typename Unit, typename T = double>
template<typename U >
static constexpr quantity_t util::quantities::concepts::Quantity< Unit, T >::castFrom ( value)
inlinestatic

Returns a new quantity initialized with the specified value.

Template Parameters
Utype to initialize the quantity with
Parameters
valuethe value to initialize the quantity with
Returns
a new Quantity object initialized with value

The value is cast into value_t via static_cast().

Example: be Tick a quantity based on an integral value, like util::quantities::tick, and detClocks an instance of detinfo::DetectorClocks:

double const tickDuration = detClocks.OpticalClock().TickPeriod();
auto const triggerTick
= Tick::castFrom(detClocks.TriggerTime() / tickDuration);

triggerTick will be of type Tick and will denote the number of the tick (0-based) within which detClocks.TriggerTime() fell.

Definition at line 825 of file quantities.h.

826  { return quantity_t{ static_cast<value_t>(value) }; }
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
T value_t
Type of the stored value.
Definition: quantities.h:570
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename Unit, typename T = double>
template<typename OQ >
constexpr OQ util::quantities::concepts::Quantity< Unit, T >::convertInto ( ) const
inline

Convert this quantity into the specified one.

Definition at line 801 of file quantities.h.

801 { return OQ(*this); }
template<typename Unit, typename T = double>
template<typename U >
static constexpr bool util::quantities::concepts::Quantity< Unit, T >::hasCompatibleValue ( )
inlinestatic

Returns whether U has (or is) a value type compatible with value_t.

Definition at line 792 of file quantities.h.

793  { return quantity_t::has_compatible_value_v<U>; }
template<typename Unit, typename T = double>
template<typename U >
static constexpr bool util::quantities::concepts::Quantity< Unit, T >::isCompatibleValue ( )
inlinestatic

Returns whether U is a value type compatible with value_t.

Definition at line 786 of file quantities.h.

787  { return quantity_t::is_compatible_value_v<U>; }
template<typename Unit, typename T = double>
template<typename OU , typename OT >
constexpr quantity_t util::quantities::concepts::Quantity< Unit, T >::minus ( Quantity< OU, OT > const  other) const

Returns a quantity difference of this and other.

template<typename Unit, typename T = double>
template<typename OU , typename OT >
constexpr auto util::quantities::concepts::Quantity< Unit, T >::minus ( Quantity< OU, OT > const  other) const -> quantity_t

Definition at line 1340 of file quantities.h.

1342 {
1343  static_assert
1344  (sameBaseUnitAs<OU>(), "Can't subtract quantities with different base unit");
1345 
1346  // if the two quantities have the same *scaled* unit, add
1347  if constexpr (sameUnitAs<OU>()) {
1348  return quantity_t(fValue - other.value());
1349  return *this;
1350  }
1351  else {
1352  // otherwise, they have same base unit but different scale: convert `other`
1353  return (*this - quantity_t(other));
1354  }
1355 } // util::quantities::concepts::Quantity<>::minus()
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
value_t fValue
Stored value.
Definition: quantities.h:830
template<typename Unit, typename T = double>
constexpr util::quantities::concepts::Quantity< Unit, T >::operator value_t ( ) const
inlineexplicit

Explicit conversion to the base quantity.

Definition at line 612 of file quantities.h.

613  { return value(); }
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
template<typename U , typename T >
template<typename OU , typename OT >
constexpr bool util::quantities::concepts::Quantity< U, T >::operator!= ( Quantity< OU, OT > const  other) const

Definition at line 1448 of file quantities.h.

1449 {
1450  static_assert
1451  (sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1452 
1453  // if the two quantities have the same *scaled* unit, just compare the values
1454  if constexpr (sameUnitAs<OU>()) {
1455  return value() != other.value();
1456  }
1457  else {
1458  // otherwise, they have same base unit but different scale: convert `other`
1459  return *this != quantity_t(other);
1460  }
1461 } // util::quantities::concepts::Quantity<>::operator!=()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename Unit, typename T = double>
template<typename OT >
std::enable_if_t<std::is_arithmetic_v<OT>, quantity_t&> util::quantities::concepts::Quantity< Unit, T >::operator*= ( OT  factor)
inline

Scale this quantity by a factor.

Definition at line 679 of file quantities.h.

679 { fValue *= factor; return *this; }
value_t fValue
Stored value.
Definition: quantities.h:830
template<typename Unit, typename T = double>
template<typename OU , typename OT >
constexpr quantity_t util::quantities::concepts::Quantity< Unit, T >::operator+ ( Quantity< OU, OT > const  other) const

Returns a quantity sum of this and other (must have same unit).

template<typename Unit, typename T = double>
constexpr quantity_t util::quantities::concepts::Quantity< Unit, T >::operator+ ( ) const
inline

Returns a quantity with same value.

Definition at line 687 of file quantities.h.

687 { return quantity_t(value()); }
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename Unit, typename T = double>
template<typename OU , typename OT >
constexpr auto util::quantities::concepts::Quantity< Unit, T >::operator+ ( Quantity< OU, OT > const  other) const -> quantity_t

Definition at line 1290 of file quantities.h.

1292 {
1293  static_assert(std::is_same<Quantity<OU, OT>, quantity_t>(),
1294  "Only quantities with exactly the same unit can be added."
1295  );
1296  return quantity_t(value() + other.value());
1297 } // util::quantities::concepts::Quantity<>::operator+
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename Unit, typename T = double>
template<typename OU , typename OT >
quantity_t& util::quantities::concepts::Quantity< Unit, T >::operator+= ( Quantity< OU, OT > const  other)

Add the other quantity (possibly concerted) to this one.

template<typename Unit, typename T = double>
template<typename OU , typename OT >
auto util::quantities::concepts::Quantity< Unit, T >::operator+= ( Quantity< OU, OT > const  other) -> quantity_t&

Definition at line 1383 of file quantities.h.

1385 {
1386  static_assert
1387  (sameBaseUnitAs<OU>(), "Can't add quantities with different base unit");
1388 
1389  // if the two quantities have the same *scaled* unit, add
1390  if constexpr (sameUnitAs<OU>()) {
1391  fValue += other.value();
1392  return *this;
1393  }
1394  else {
1395  // otherwise, they have same base unit but different scale: convert `other`
1396  return (*this += quantity_t(other));
1397  }
1398 } // util::quantities::concepts::Quantity<>::operator+=()
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
value_t fValue
Stored value.
Definition: quantities.h:830
template<typename Unit, typename T = double>
template<typename OU , typename OT >
constexpr quantity_t util::quantities::concepts::Quantity< Unit, T >::operator- ( Quantity< OU, OT > const  other) const

Returns a quantity difference of this and other (must have same unit).

template<typename Unit, typename T = double>
constexpr quantity_t util::quantities::concepts::Quantity< Unit, T >::operator- ( ) const
inline

Returns a quantity with same value but the sign flipped.

Definition at line 690 of file quantities.h.

690 { return quantity_t(-value()); }
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename Unit, typename T = double>
template<typename OU , typename OT >
constexpr auto util::quantities::concepts::Quantity< Unit, T >::operator- ( Quantity< OU, OT > const  other) const -> quantity_t

Definition at line 1304 of file quantities.h.

1306 {
1307  static_assert(std::is_same<Quantity<OU, OT>, quantity_t>(),
1308  "Only quantities with exactly the same unit can be subtracted."
1309  );
1310  return quantity_t(value() - other.value());
1311 } // util::quantities::concepts::Quantity<>::operator+
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename Unit, typename T = double>
template<typename OU , typename OT >
quantity_t& util::quantities::concepts::Quantity< Unit, T >::operator-= ( Quantity< OU, OT > const  other)

Subtract the other quantity (possibly concerted) to this one.

template<typename Unit, typename T = double>
template<typename OU , typename OT >
auto util::quantities::concepts::Quantity< Unit, T >::operator-= ( Quantity< OU, OT > const  other) -> quantity_t&

Definition at line 1405 of file quantities.h.

1407 {
1408  static_assert(sameBaseUnitAs<OU>(),
1409  "Can't subtract quantities with different base unit"
1410  );
1411 
1412  // if the two quantities have the same *scaled* unit, add
1413  if constexpr (sameUnitAs<OU>()) {
1414  fValue -= other.value();
1415  return *this;
1416  }
1417  else {
1418  // otherwise, they have same base unit but different scale: convert `other`
1419  return (*this -= quantity_t(other));
1420  }
1421 } // util::quantities::concepts::Quantity<>::operator-=()
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
value_t fValue
Stored value.
Definition: quantities.h:830
template<typename Unit, typename T = double>
template<typename OU , typename OT >
constexpr value_t util::quantities::concepts::Quantity< Unit, T >::operator/ ( Quantity< OU, OT >  q) const

Division by a quantity, returns a pure number.

template<typename Unit, typename T = double>
template<typename OU , typename OT >
constexpr auto util::quantities::concepts::Quantity< Unit, T >::operator/ ( Quantity< OU, OT > const  q) const -> value_t

Definition at line 1362 of file quantities.h.

1364 {
1365  static_assert
1366  (sameBaseUnitAs<OU>(), "Can't divide quantities with different base unit");
1367 
1368  // if the two quantities have the same *scaled* unit, divide
1369  if constexpr (sameUnitAs<OU>()) {
1370  return value() / q.value();
1371  }
1372  else {
1373  // otherwise, they have same base unit but different scale: convert `other`
1374  return (*this) / quantity_t(q);
1375  }
1376 } // util::quantities::concepts::Quantity<>::operator/(Quantity)
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename Unit, typename T = double>
template<typename OT >
std::enable_if_t<std::is_arithmetic_v<OT>, quantity_t&> util::quantities::concepts::Quantity< Unit, T >::operator/= ( OT  quot)
inline

Scale the quantity dividing it by a quotient.

Definition at line 684 of file quantities.h.

684 { fValue /= quot; return *this; }
value_t fValue
Stored value.
Definition: quantities.h:830
template<typename U , typename T >
template<typename OU , typename OT >
constexpr bool util::quantities::concepts::Quantity< U, T >::operator< ( Quantity< OU, OT > const  other) const

Definition at line 1508 of file quantities.h.

1509 {
1510  static_assert
1511  (sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1512 
1513  // if the two quantities have the same *scaled* unit, just compare the values
1514  if constexpr (sameUnitAs<OU>()) {
1515  return value() < other.value();
1516  }
1517  else {
1518  // otherwise, they have same base unit but different scale: convert `other`
1519  return *this < quantity_t(other);
1520  }
1521 } // util::quantities::concepts::Quantity<>::operator<()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename U , typename T >
template<typename OU , typename OT >
constexpr bool util::quantities::concepts::Quantity< U, T >::operator<= ( Quantity< OU, OT > const  other) const

Definition at line 1468 of file quantities.h.

1469 {
1470  static_assert
1471  (sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1472 
1473  // if the two quantities have the same *scaled* unit, just compare the values
1474  if constexpr (sameUnitAs<OU>()) {
1475  return value() <= other.value();
1476  }
1477  else {
1478  // otherwise, they have same base unit but different scale: convert `other`
1479  return *this <= quantity_t(other);
1480  }
1481 } // util::quantities::concepts::Quantity<>::operator<=()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename U , typename T >
template<typename OU , typename OT >
constexpr bool util::quantities::concepts::Quantity< U, T >::operator== ( Quantity< OU, OT > const  other) const

Definition at line 1428 of file quantities.h.

1429 {
1430  static_assert
1431  (sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1432 
1433  // if the two quantities have the same *scaled* unit, just compare the values
1434  if constexpr (sameUnitAs<OU>()) {
1435  return value() == other.value();
1436  }
1437  else {
1438  // otherwise, they have same base unit but different scale: convert `other`
1439  return *this == quantity_t(other);
1440  }
1441 } // util::quantities::concepts::Quantity<>::operator==()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename U , typename T >
template<typename OU , typename OT >
constexpr bool util::quantities::concepts::Quantity< U, T >::operator> ( Quantity< OU, OT > const  other) const

Definition at line 1528 of file quantities.h.

1529 {
1530  static_assert
1531  (sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1532 
1533  // if the two quantities have the same *scaled* unit, just compare the values
1534  if constexpr (sameUnitAs<OU>()) {
1535  return value() > other.value();
1536  }
1537  else {
1538  // otherwise, they have same base unit but different scale: convert `other`
1539  return *this > quantity_t(other);
1540  }
1541 } // util::quantities::concepts::Quantity<>::operator>()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename U , typename T >
template<typename OU , typename OT >
constexpr bool util::quantities::concepts::Quantity< U, T >::operator>= ( Quantity< OU, OT > const  other) const

Definition at line 1488 of file quantities.h.

1489 {
1490  static_assert
1491  (sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1492 
1493  // if the two quantities have the same *scaled* unit, just compare the values
1494  if constexpr (sameUnitAs<OU>()) {
1495  return value() >= other.value();
1496  }
1497  else {
1498  // otherwise, they have same base unit but different scale: convert `other`
1499  return *this >= quantity_t(other);
1500  }
1501 } // util::quantities::concepts::Quantity<>::operator>=()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:609
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
template<typename Unit, typename T = double>
template<typename OU , typename OT >
constexpr quantity_t util::quantities::concepts::Quantity< Unit, T >::plus ( Quantity< OU, OT > const  other) const

Returns a quantity sum of this and other.

template<typename Unit, typename T = double>
template<typename OU , typename OT >
constexpr auto util::quantities::concepts::Quantity< Unit, T >::plus ( Quantity< OU, OT > const  other) const -> quantity_t

Definition at line 1318 of file quantities.h.

1320 {
1321  static_assert
1322  (sameBaseUnitAs<OU>(), "Can't add quantities with different base unit");
1323 
1324  // if the two quantities have the same *scaled* unit, add
1325  if constexpr (sameUnitAs<OU>()) {
1326  return quantity_t(fValue + other.value());
1327  return *this;
1328  }
1329  else {
1330  // otherwise, they have same base unit but different scale: convert `other`
1331  return (*this + quantity_t(other));
1332  }
1333 } // util::quantities::concepts::Quantity<>::operator+()
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:572
value_t fValue
Stored value.
Definition: quantities.h:830
template<typename Unit, typename T = double>
template<typename OU >
static constexpr bool util::quantities::concepts::Quantity< Unit, T >::sameBaseUnitAs ( )
inlinestatic

Returns whether this quantity has the same base unit as OU.

Parameters
OUany type with baseunit_t type (including ScaledUnit, Quantity, Interval...)

Definition at line 762 of file quantities.h.

763  { return unit_t::template sameBaseUnitAs<OU>(); }
template<typename Unit, typename T = double>
template<typename OU >
static constexpr bool util::quantities::concepts::Quantity< Unit, T >::sameUnitAs ( )
inlinestatic

Returns whether this quantity has same unit and scale as OU.

Parameters
OUany type with unit_t type (including ScaledUnit, Quantity, Interval...)

Definition at line 771 of file quantities.h.

772  { return unit_t::template sameUnitAs<OU>(); }
template<typename Unit, typename T = double>
static constexpr unit_t util::quantities::concepts::Quantity< Unit, T >::unit ( )
inlinestatic

Returns an object with as type the scaled unit (unit_t).

Definition at line 745 of file quantities.h.

745 { return {}; }
template<typename Unit, typename T = double>
static auto util::quantities::concepts::Quantity< Unit, T >::unitName ( )
inlinestatic

Returns the full name of the unit, in a string-like object.

Definition at line 751 of file quantities.h.

751 { return unit_t::name(); }
then echo fcl name
template<typename Unit, typename T = double>
static auto util::quantities::concepts::Quantity< Unit, T >::unitSymbol ( )
inlinestatic

Returns the symbol of the unit, in a string-like object.

Definition at line 754 of file quantities.h.

754 { return unit_t::symbol(); }
template<typename Unit, typename T = double>
constexpr value_t util::quantities::concepts::Quantity< Unit, T >::value ( ) const
inline

Returns the value of the quantity.

Definition at line 609 of file quantities.h.

609 { return fValue; }
value_t fValue
Stored value.
Definition: quantities.h:830

Member Data Documentation

template<typename Unit, typename T = double>
value_t util::quantities::concepts::Quantity< Unit, T >::fValue {}
private

Stored value.

Definition at line 830 of file quantities.h.

template<typename Unit, typename T = double>
template<typename U >
constexpr bool util::quantities::concepts::Quantity< Unit, T >::has_compatible_value_v = details::has_value_compatible_with_v<U, value_t>
static

Whether U has (or is) a value type compatible with value_t.

Definition at line 782 of file quantities.h.

template<typename Unit, typename T = double>
template<typename U >
constexpr bool util::quantities::concepts::Quantity< Unit, T >::is_compatible_value_v = details::is_value_compatible_with_v<U, value_t>
static

Whether U is a value type compatible with value_t.

Definition at line 777 of file quantities.h.


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