|
| constexpr | quantity ()=default |
| | Constructs a zero quantity.
|
| |
| | quantity (const quantity &)=default |
| |
template<typename Rep2 >
requires std::convertible_to<const Rep2&, rep> && (treat_as_inexact_v<rep> || !treat_as_inexact_v<Rep2>) |
| constexpr | quantity (const Rep2 &r) |
| | Constructs from a tick count.
|
| |
template<typename Rep2 , typename Precision2 >
requires std::convertible_to<const Rep2&, rep> && detail::_lossless_conversion<Rep2, Precision2, rep, precision> && detail::_quantity_castable<quantity<Unit, Rep2, Precision2>, quantity> |
| constexpr | quantity (const quantity< Unit, Rep2, Precision2 > &q) |
| | Constructs from another quantity of the same unit with different representation or precision.
|
| |
template<typename Rep2 , typename Precision2 >
requires (!detail::_lossless_conversion<Rep2, Precision2, rep, precision> || !std::convertible_to<const Rep2&, rep>) && detail::_quantity_castable<quantity<Unit, Rep2, Precision2>, quantity> |
| constexpr | quantity (const quantity< Unit, Rep2, Precision2 > &q) |
| | Explicit constructor for lossy conversions.
|
| |
| | ~quantity ()=default |
| |
| quantity & | operator= (const quantity &)=default |
| |
| constexpr rep | count () const |
| | Returns the tick count.
|
| |
| constexpr quantity< Unit, typename std::common_type< rep >::type, precision > | operator+ () const |
| |
| constexpr quantity< Unit, typename std::common_type< rep >::type, precision > | operator- () const |
| |
| constexpr quantity & | operator++ () |
| |
| constexpr quantity | operator++ (int) |
| |
| constexpr quantity & | operator-- () |
| |
| constexpr quantity | operator-- (int) |
| |
| constexpr quantity & | operator+= (const quantity &q) |
| |
| constexpr quantity & | operator-= (const quantity &q) |
| |
| constexpr quantity & | operator*= (const rep &r) |
| |
| constexpr quantity & | operator/= (const rep &r) |
| |
| constexpr quantity & | operator%= (const rep &r) |
| |
| constexpr quantity & | operator%= (const quantity &q) |
| |
template<typename Unit, typename Rep, typename Precision>
class quanta::electro::quantity< Unit, Rep, Precision >
A quantity of an electrical unit with a representation and precision.
Similar to std::chrono::duration, quantity represents an amount of some electrical unit (volts, amperes, ohms, ...). The precision is expressed as a std::ratio of one base unit.
Examples
auto usb = 5_V;
auto sum = 1000_mV + 500_mV;
auto ratio = 10_kOhm / 5_kOhm;
auto v = 100_mA * 2_kOhm;
auto p = 12_V * 2_A;
voltage< int64_t, std::milli > millivolts
Voltage with 1 mV precision.
resistance< int64_t, std::kilo > kiloohms
Resistance with 1 kΩ precision.
constexpr scaled_t scaled
Selects the scaled form in to_string().
- Template Parameters
-
| Unit | The unit tag type (volt_unit, ampere_unit, ...). |
| Rep | Arithmetic type for the tick count. |
| Precision | A std::ratio representing the precision (default: 1). |
Definition at line 245 of file electro.hpp.
template<typename Unit , typename Rep , typename Precision >
template<typename Rep2 >
requires std::convertible_to<const Rep2&,
rep> && (treat_as_inexact_v<
rep> || !treat_as_inexact_v<Rep2>)
Constructs from a tick count.
Implicit for inexact types, explicit otherwise to prevent accidental precision loss.
- Template Parameters
-
| Rep2 | The source representation type. |
- Parameters
-
Definition at line 273 of file electro.hpp.
template<typename Unit , typename Rep , typename Precision >
template<typename Rep2 , typename Precision2 >
requires std::convertible_to<const Rep2&,
rep> && detail::_lossless_conversion<Rep2, Precision2,
rep,
precision> && detail::_quantity_castable<
quantity<Unit, Rep2, Precision2>,
quantity>
Constructs from another quantity of the same unit with different representation or precision.
Implicit when the conversion is lossless (the target rep is floating-point, or the target precision evenly divides the source precision and the source rep is not floating-point) and the source rep converts implicitly to the target rep. Any other conversion that the cast can perform is explicit (see below).
- Template Parameters
-
| Rep2 | Source representation type. |
| Precision2 | Source precision. |
- Parameters
-
Definition at line 294 of file electro.hpp.
template<typename Unit , typename Rep , typename Precision >
template<typename Rep2 , typename Precision2 >
requires (!detail::_lossless_conversion<Rep2, Precision2,
rep,
precision> || !std::convertible_to<const Rep2&,
rep>) && detail::_quantity_castable<
quantity<Unit, Rep2, Precision2>,
quantity>
Explicit constructor for lossy conversions.
Every conversion that the cast can perform and that is not implicit (see above) is explicit: a lossy one (to a coarser precision, or from a floating-point rep to an integral one), or one to a rep that the source rep converts to only explicitly. The value is that of the domain's cast, truncated toward zero. The cast can perform the conversion when the conversion factor between the precisions fits in a std::ratio and the reps are integral or have a common type with intmax_t through which the count converts.
- Template Parameters
-
| Rep2 | Source representation type. |
| Precision2 | Source precision. |
- Parameters
-
Definition at line 317 of file electro.hpp.