An interval (duration, length, distance) between two quantity points. More...
#include <intervals.h>
Public Types | |
using | category_base_t = details::WithCategory< Cat > |
using | traits_t = typename category_base_t::traits_t |
Traits of the category. More... | |
template<typename OC , typename Type = void> | |
using | enable_if_compatible_t = std::enable_if_t< category_base_t::template category_compatible_with< OC >(), Type > |
using | interval_t = Interval< Q, Cat > |
This type. More... | |
Types from the base quantity | |
using | quantity_t = Q |
using | category_t = typename category_base_t::category_t |
Quantity the interval is based on. More... | |
template<typename R > | |
using | scaled_quantity_t = rescale< quantity_t, R > |
A quantity in the same unit, but possibly a different scale. More... | |
using | value_t = typename quantity_t::value_t |
Type of the stored value. More... | |
using | unit_t = typename quantity_t::unit_t |
Description of the scaled unit. More... | |
using | baseunit_t = typename quantity_t::baseunit_t |
Description of the unscaled unit. More... | |
template<typename OQ , typename OI > | |
using | other_interval_t = Interval< OQ, category_t > |
An interval based on a different quantity but with the same category. More... | |
Public Types inherited from util::quantities::concepts::details::WithCategory< Cat > | |
using | category_t = Cat |
The category of this object. More... | |
using | traits_t = category_traits< category_t > |
Traits of this category. More... | |
Public Member Functions | |
Interval ()=default | |
Constructor: value is left uninitialized. More... | |
constexpr | Interval (value_t v) |
Constructor: takes a value in the intended representation. More... | |
template<typename... Args> | |
constexpr | Interval (Quantity< Args...> const &q) |
Constructor: converts from a quantity. More... | |
template<typename IV , typename std::enable_if_t< is_interval_v< IV >> * = nullptr> | |
constexpr | Interval (IV iv) |
Constructor: converts from another interval. More... | |
constexpr quantity_t const & | quantity () const |
Returns the value of the interval as a quantity. More... | |
constexpr | operator value_t () const |
Conversion to the base quantity. More... | |
template<typename IV > | |
constexpr IV | convertInto () const |
Convert this interval into the specified one. More... | |
Asymmetric operand arithmetic operations | |
These arithmetic operations take care of preserving the interval unit 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.
| |
constexpr interval_t | operator+ (interval_t const other) const |
constexpr interval_t | operator- (interval_t const other) const |
template<typename OQ , typename OC > | |
constexpr enable_if_compatible_t < Interval< OQ, OC >, value_t > | operator/ (Interval< OQ, OC > const denom) const |
Division by an interval, returns a pure number. More... | |
template<typename R > | |
interval_t & | operator+= (scaled_quantity_t< R > const other) |
Add a quantity (possibly converted) to this one. More... | |
template<typename OQ , typename OC > | |
enable_if_compatible_t < Interval< OQ, OC > , interval_t & > | operator+= (Interval< OQ, OC > const other) |
Add the other interval (possibly converted) to this one. More... | |
template<typename R > | |
interval_t & | operator-= (scaled_quantity_t< R > const other) |
Subtract a quantity (possibly converted) from this one. More... | |
template<typename OQ , typename OC > | |
enable_if_compatible_t < Interval< OQ, OC > , interval_t & > | operator-= (Interval< OQ, OC > const other) |
Subtract the other interval (possibly converted) from this one. More... | |
template<typename T > | |
interval_t & | operator*= (T factor) |
Scale this interval by a factor. More... | |
template<typename T > | |
interval_t & | operator/= (T factor) |
Scale the interval dividing it by a quotient. More... | |
constexpr interval_t | operator+ () const |
Returns an interval with same value. More... | |
constexpr interval_t | operator- () const |
Returns an interval with same value but the sign flipped. More... | |
constexpr interval_t | abs () const |
Returns an interval 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
Value storage types are compared according to C++ rules. | |
template<typename OQ , typename OC > | |
constexpr enable_if_compatible_t < Interval< OQ, OC >, bool > | operator== (Interval< OQ, OC > const other) const |
template<typename OQ , typename OC > | |
constexpr enable_if_compatible_t < Interval< OQ, OC >, bool > | operator!= (Interval< OQ, OC > const other) const |
template<typename OQ , typename OC > | |
constexpr enable_if_compatible_t < Interval< OQ, OC >, bool > | operator>= (Interval< OQ, OC > const other) const |
template<typename OQ , typename OC > | |
constexpr enable_if_compatible_t < Interval< OQ, OC >, bool > | operator> (Interval< OQ, OC > const other) const |
template<typename OQ , typename OC > | |
constexpr enable_if_compatible_t < Interval< OQ, OC >, bool > | operator<= (Interval< OQ, OC > const other) const |
template<typename OQ , typename OC > | |
constexpr enable_if_compatible_t < Interval< OQ, OC >, bool > | operator< (Interval< OQ, OC > const other) const |
Static Public Member Functions | |
template<typename U > | |
static interval_t | castFrom (U value) |
Returns a new interval initialized with the specified value. More... | |
Access to the scaled unit. | |
template<typename OU > | |
static constexpr bool | sameBaseUnitAs () |
Returns whether objects of type OU have the same base unit as this. More... | |
template<typename OU > | |
static constexpr bool | sameUnitAs () |
Returns whether objects of type OU have same unit and scale as this. More... | |
Static Public Member Functions inherited from util::quantities::concepts::details::WithCategory< Cat > | |
static constexpr category_t | category () |
Returns an instance of the category of this object. More... | |
static constexpr bool | hasCategoryName () |
Returns whether this category has a name. More... | |
static std::string | categoryName () |
Returns the name of the category of this object. More... | |
template<typename OC > | |
static constexpr bool | same_category_as () |
Returns whether the type OC belongs to category_t . More... | |
template<typename OC > | |
static constexpr bool | same_category_as (OC const &) |
template<typename OC > | |
static constexpr bool | category_compatible_with () |
Returns whether OC has a category compatible with this one. More... | |
template<typename OC > | |
static constexpr bool | category_compatible_with (OC const &) |
An interval (duration, length, distance) between two quantity points.
Q | quantity the interval is based on |
An interval shares most of the concepts of a Quantity
, but it interacts only with other intervals rather than with bare Quantity
objects, with the exception of construction. In this sense, the relation between Interval
and Quantity
is similar to the one between Quantity
and its base type (Quantity::value_t
).
In addition, an interval can be added to a quantity point (Point
) to translate it, and it can be obtained as difference between two quantity points.
Definition at line 114 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::baseunit_t = typename quantity_t::baseunit_t |
Description of the unscaled unit.
Definition at line 152 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::category_base_t = details::WithCategory<Cat> |
Definition at line 116 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::category_t = typename category_base_t::category_t |
Quantity the interval is based on.
The category this point belongs to.
Definition at line 139 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::enable_if_compatible_t = std::enable_if_t <category_base_t::template category_compatible_with<OC>(), Type> |
Definition at line 125 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::interval_t = Interval<Q, Cat> |
This type.
Definition at line 129 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::other_interval_t = Interval<OQ, category_t> |
An interval based on a different quantity but with the same category.
Definition at line 156 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::quantity_t = Q |
Definition at line 136 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::scaled_quantity_t = rescale<quantity_t, R> |
A quantity in the same unit, but possibly a different scale.
Definition at line 143 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::traits_t = typename category_base_t::traits_t |
Traits of the category.
Definition at line 119 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::unit_t = typename quantity_t::unit_t |
Description of the scaled unit.
Definition at line 149 of file intervals.h.
using util::quantities::concepts::Interval< Q, Cat >::value_t = typename quantity_t::value_t |
Type of the stored value.
Definition at line 146 of file intervals.h.
|
explicitdefault |
Constructor: value is left uninitialized.
|
inlineexplicit |
Constructor: takes a value in the intended representation.
Definition at line 167 of file intervals.h.
|
inline |
Constructor: converts from a quantity.
OQ | type of the quantity |
q | quantity to be converted from |
The quantity is required to be in the same unit as this interval (unit scale may differ). The value in q
is converted from its native scale into the one of this interval.
Definition at line 180 of file intervals.h.
|
inline |
Constructor: converts from another interval.
I | type of the other interval |
iv | interval to be converted from |
Intervals are required to be in the same unit (unit scale may differ). The value in iv
is converted from its native scale into the one of this interval.
Definition at line 195 of file intervals.h.
|
inline |
Returns an interval with the absolute value of this one.
Definition at line 329 of file intervals.h.
|
inlinestatic |
Returns a new interval initialized with the specified value.
U | type to initialize the quantity with |
value | the value to initialize the interval with |
Interval
object initialized with value
The value
is cast into value_t
via static_cast()
.
Definition at line 400 of file intervals.h.
|
inline |
Convert this interval into the specified one.
Definition at line 389 of file intervals.h.
|
inlineexplicit |
|
inline |
Definition at line 360 of file intervals.h.
|
inline |
Scale this interval by a factor.
Definition at line 314 of file intervals.h.
|
inline |
Returns an interval sum of this and other
(must have exactly the same unit and scale).
Definition at line 276 of file intervals.h.
|
inline |
Returns an interval with same value.
Definition at line 323 of file intervals.h.
|
inline |
Add a quantity (possibly converted) to this one.
Definition at line 292 of file intervals.h.
|
inline |
Add the other
interval (possibly converted) to this one.
Definition at line 298 of file intervals.h.
|
inline |
Returns an interval difference of this and other
(must have exactly the same unit and scale).
Definition at line 281 of file intervals.h.
|
inline |
Returns an interval with same value but the sign flipped.
Definition at line 326 of file intervals.h.
|
inline |
Subtract a quantity (possibly converted) from this one.
Definition at line 303 of file intervals.h.
|
inline |
Subtract the other
interval (possibly converted) from this one.
Definition at line 309 of file intervals.h.
|
inline |
Division by an interval, returns a pure number.
Definition at line 287 of file intervals.h.
|
inline |
Scale the interval dividing it by a quotient.
Definition at line 319 of file intervals.h.
|
inline |
Definition at line 380 of file intervals.h.
|
inline |
Definition at line 375 of file intervals.h.
|
inline |
Definition at line 355 of file intervals.h.
|
inline |
Definition at line 370 of file intervals.h.
|
inline |
Definition at line 365 of file intervals.h.
|
inline |
Returns the value of the interval as a quantity.
Definition at line 198 of file intervals.h.
|
inlinestatic |
Returns whether objects of type OU
have the same base unit as this.
Definition at line 229 of file intervals.h.
|
inlinestatic |
Returns whether objects of type OU
have same unit and scale as this.
Definition at line 234 of file intervals.h.