LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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
 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:

  • a Quantity type will carry the information of its unit with the type
  • quantities must be assigned other quantities: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} using util::quantities::milliampere;

    milliampere i; i = 2.5; // ERROR! what is 2.5? i = milliampere(2.5);

    milliampere i2 { 2.5 }; // SPECIAL, allowed only in construction i2 = i1; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • can be converted, implicitly or explicitly, to its plain value: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} using util::quantities::milliampere;

    milliampere i { 6.0 }; double v = i; // implicit conversion v = double(i); // explicit conversion v = i.value(); // even more explicit conversion ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • weakly resists attempts to mess with units ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} milliampere mi { 4.0 }; microampere ui { 500.0 }; mi = ui; // now mi == 0.5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • weakly attempts to preserve the unit information ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} using namespace util::quantities; using namespace util::quantities::electronics_literals;

    milliampere mi { 4.0 }; microampere ui { 500.0 };

    mi += ui; // 4.5 mA mi *= ui; // ERROR! what does this even mean?? mi += 5.0; // ERROR! mi += milliampere(3.0); // 7.5 mA mi += 2.0_ma; // 9.5 mA mi + ui; // ERROR! (arbitrary whether to represent in mA or uA) mi + 5.0; // ERROR! (as above) mi / 5.0; // milliampere{1.9} mi - 5_mA; // milliampere{4.5} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(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

  • method signatures usually pass Quantity objects by value; it is assumed that the type T is simple enough that copying it is faster than passing around its reference, and that any overhead is optimized out by the compiler

Definition at line 554 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 562 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 559 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 558 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 557 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 570 of file quantities.h.

570 : fValue(v) {}
value_t fValue
Stored value.
Definition: quantities.h:822
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 582 of file quantities.h.

583  : fValue{unit_t::template fromRepr<typename Q::unit_t::ratio>(q.value())}
584  {
585  static_assert(sameBaseUnitAs<Q>(),
586  "Can't construct from quantity with different base unit");
587  }
value_t fValue
Stored value.
Definition: quantities.h:822

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 679 of file quantities.h.

References util::abs(), util::quantities::concepts::operator!=(), util::quantities::concepts::operator==(), util::quantities::concepts::operator>(), util::quantities::concepts::operator>=(), fhicl::other, and value.

679 { 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:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 731 of file quantities.h.

731 { 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 816 of file quantities.h.

References value.

Referenced by util::quantities::electronics_literals::operator""_tick(), and util::quantities::electronics_literals::operator""_tickd().

817  {
818  return quantity_t{static_cast<value_t>(value)};
819  }
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
T value_t
Type of the stored value.
Definition: quantities.h:557
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 790 of file quantities.h.

791  {
792  return OQ(*this);
793  }
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 780 of file quantities.h.

781  {
782  return quantity_t::has_compatible_value_v<U>;
783  }
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 772 of file quantities.h.

773  {
774  return quantity_t::is_compatible_value_v<U>;
775  }
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 1286 of file quantities.h.

References fhicl::other.

1288 {
1289  static_assert(sameBaseUnitAs<OU>(), "Can't subtract quantities with different base unit");
1290 
1291  // if the two quantities have the same *scaled* unit, add
1292  if constexpr (sameUnitAs<OU>()) {
1293  return quantity_t(fValue - other.value());
1294  return *this;
1295  }
1296  else {
1297  // otherwise, they have same base unit but different scale: convert `other`
1298  return (*this - quantity_t(other));
1299  }
1300 } // util::quantities::concepts::Quantity<>::minus()
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
value_t fValue
Stored value.
Definition: quantities.h:822
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 593 of file quantities.h.

References util::quantities::concepts::operator+(), lar::dump::operator+=(), util::quantities::concepts::operator-(), util::quantities::concepts::operator/(), fhicl::other, and value.

593 { return value(); }
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
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 1375 of file quantities.h.

References value, and util::quantities::concepts::Quantity< Unit, T >::value().

1377 {
1378  static_assert(sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1379 
1380  // if the two quantities have the same *scaled* unit, just compare the values
1381  if constexpr (sameUnitAs<OU>()) { return value() != other.value(); }
1382  else {
1383  // otherwise, they have same base unit but different scale: convert `other`
1384  return *this != quantity_t(other);
1385  }
1386 } // util::quantities::concepts::Quantity<>::operator!=()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 658 of file quantities.h.

659  {
660  fValue *= factor;
661  return *this;
662  }
value_t fValue
Stored value.
Definition: quantities.h:822
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 673 of file quantities.h.

References value.

673 { return quantity_t(value()); }
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 1245 of file quantities.h.

References fhicl::other, and value.

1247 {
1248  static_assert(std::is_same<Quantity<OU, OT>, quantity_t>(),
1249  "Only quantities with exactly the same unit can be added.");
1250  return quantity_t(value() + other.value());
1251 } // util::quantities::concepts::Quantity<>::operator+
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 1321 of file quantities.h.

References fhicl::other.

1323 {
1324  static_assert(sameBaseUnitAs<OU>(), "Can't add quantities with different base unit");
1325 
1326  // if the two quantities have the same *scaled* unit, add
1327  if constexpr (sameUnitAs<OU>()) {
1328  fValue += other.value();
1329  return *this;
1330  }
1331  else {
1332  // otherwise, they have same base unit but different scale: convert `other`
1333  return (*this += quantity_t(other));
1334  }
1335 } // util::quantities::concepts::Quantity<>::operator+=()
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
value_t fValue
Stored value.
Definition: quantities.h:822
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 676 of file quantities.h.

References value.

676 { return quantity_t(-value()); }
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 1256 of file quantities.h.

References fhicl::other, and value.

1258 {
1259  static_assert(std::is_same<Quantity<OU, OT>, quantity_t>(),
1260  "Only quantities with exactly the same unit can be subtracted.");
1261  return quantity_t(value() - other.value());
1262 } // util::quantities::concepts::Quantity<>::operator+
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 1340 of file quantities.h.

References fhicl::other.

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

References value.

1307 {
1308  static_assert(sameBaseUnitAs<OU>(), "Can't divide quantities with different base unit");
1309 
1310  // if the two quantities have the same *scaled* unit, divide
1311  if constexpr (sameUnitAs<OU>()) { return value() / q.value(); }
1312  else {
1313  // otherwise, they have same base unit but different scale: convert `other`
1314  return (*this) / quantity_t(q);
1315  }
1316 } // util::quantities::concepts::Quantity<>::operator/(Quantity)
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 666 of file quantities.h.

667  {
668  fValue /= quot;
669  return *this;
670  }
value_t fValue
Stored value.
Definition: quantities.h:822
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 1423 of file quantities.h.

References value, and util::quantities::concepts::Quantity< Unit, T >::value().

1425 {
1426  static_assert(sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1427 
1428  // if the two quantities have the same *scaled* unit, just compare the values
1429  if constexpr (sameUnitAs<OU>()) { return value() < other.value(); }
1430  else {
1431  // otherwise, they have same base unit but different scale: convert `other`
1432  return *this < quantity_t(other);
1433  }
1434 } // util::quantities::concepts::Quantity<>::operator<()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 1391 of file quantities.h.

References value, and util::quantities::concepts::Quantity< Unit, T >::value().

1393 {
1394  static_assert(sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1395 
1396  // if the two quantities have the same *scaled* unit, just compare the values
1397  if constexpr (sameUnitAs<OU>()) { return value() <= other.value(); }
1398  else {
1399  // otherwise, they have same base unit but different scale: convert `other`
1400  return *this <= quantity_t(other);
1401  }
1402 } // util::quantities::concepts::Quantity<>::operator<=()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 1359 of file quantities.h.

References value, and util::quantities::concepts::Quantity< Unit, T >::value().

1361 {
1362  static_assert(sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1363 
1364  // if the two quantities have the same *scaled* unit, just compare the values
1365  if constexpr (sameUnitAs<OU>()) { return value() == other.value(); }
1366  else {
1367  // otherwise, they have same base unit but different scale: convert `other`
1368  return *this == quantity_t(other);
1369  }
1370 } // util::quantities::concepts::Quantity<>::operator==()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 1439 of file quantities.h.

References value, and util::quantities::concepts::Quantity< Unit, T >::value().

1441 {
1442  static_assert(sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1443 
1444  // if the two quantities have the same *scaled* unit, just compare the values
1445  if constexpr (sameUnitAs<OU>()) { return value() > other.value(); }
1446  else {
1447  // otherwise, they have same base unit but different scale: convert `other`
1448  return *this > quantity_t(other);
1449  }
1450 } // util::quantities::concepts::Quantity<>::operator>()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 1407 of file quantities.h.

References value, and util::quantities::concepts::Quantity< Unit, T >::value().

1409 {
1410  static_assert(sameBaseUnitAs<OU>(), "Can't compare quantities with different base unit");
1411 
1412  // if the two quantities have the same *scaled* unit, just compare the values
1413  if constexpr (sameUnitAs<OU>()) { return value() >= other.value(); }
1414  else {
1415  // otherwise, they have same base unit but different scale: convert `other`
1416  return *this >= quantity_t(other);
1417  }
1418 } // util::quantities::concepts::Quantity<>::operator>=()
constexpr value_t value() const
Returns the value of the quantity.
Definition: quantities.h:590
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
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 1267 of file quantities.h.

References fhicl::other.

1269 {
1270  static_assert(sameBaseUnitAs<OU>(), "Can't add quantities with different base unit");
1271 
1272  // if the two quantities have the same *scaled* unit, add
1273  if constexpr (sameUnitAs<OU>()) {
1274  return quantity_t(fValue + other.value());
1275  return *this;
1276  }
1277  else {
1278  // otherwise, they have same base unit but different scale: convert `other`
1279  return (*this + quantity_t(other));
1280  }
1281 } // util::quantities::concepts::Quantity<>::operator+()
Quantity< Unit, T > quantity_t
The type of this class.
Definition: quantities.h:559
value_t fValue
Stored value.
Definition: quantities.h:822
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 745 of file quantities.h.

746  {
747  return unit_t::template sameBaseUnitAs<OU>();
748  }
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 756 of file quantities.h.

757  {
758  return unit_t::template sameUnitAs<OU>();
759  }
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 728 of file quantities.h.

Referenced by util::quantities::concepts::operator<<(), and util::quantities::concepts::to_string().

728 { 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 734 of file quantities.h.

734 { return unit_t::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 737 of file quantities.h.

737 { return unit_t::symbol(); }

Member Data Documentation

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

Stored value.

Definition at line 822 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
static
Initial value:
=
details::has_value_compatible_with_v<U, value_t>

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

Definition at line 767 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 763 of file quantities.h.


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