Public Types | List of all members
util::quantities::concepts::ScaledUnit< U, R > Struct Template Reference

#include <quantities.h>

Public Types

using baseunit_t = U
 Base, unscaled unit. More...
 
using unit_t = ScaledUnit< U, R >
 Unit with scale (i.e. this object). More...
 
using ratio = R
 The ratio to go from the base unit to this one. More...
 
using prefix_t = Prefix< ratio >
 The prefix of the unit. More...
 

Static Public Member Functions

Conversion to string.
Note
Implementation note: the returned values (currently std::string_view) are not constexpr since it takes noticeable additional effort to make them so.
static auto symbol ()
 Returns short symbol of the unit (e.g. "ns") is a string-like object. More...
 
static auto name ()
 
Representation conversions.
template<typename T >
static constexpr T scale (T v)
 Converts a value from the base unit to this one. More...
 
template<typename T >
static constexpr T unscale (T v)
 Converts a value from this scaled unit to the base one. More...
 
template<typename TargetRatio , typename T >
static constexpr T scaleTo (T v)
 Converts a value from the scaled unit to a different TargetRatio. More...
 
template<typename TargetRatio , typename T >
static constexpr T fromRepr (T v)
 Converts a value from TargetRatio scale to this scaled unit. More...
 
Type features
static constexpr prefix_t prefix ()
 Returns an instance of the prefix_t type. More...
 
static constexpr baseunit_t baseUnit ()
 Returns an instance of the baseunit_t type. More...
 
static constexpr unit_t unit ()
 Returns an instance of the unit_t type. More...
 
template<typename OU >
static constexpr bool sameBaseUnitAs ()
 Returns whether scaled unit U has the same base unit as this one. More...
 
template<typename OU >
static constexpr bool sameUnitAs ()
 Returns whether scaled unit U has the same base unit as this one. More...
 

Detailed Description

template<typename U, typename R = std::ratio<1>>
struct util::quantities::concepts::ScaledUnit< U, R >

Definition at line 394 of file quantities.h.

Member Typedef Documentation

template<typename U, typename R = std::ratio<1>>
using util::quantities::concepts::ScaledUnit< U, R >::baseunit_t = U

Base, unscaled unit.

Definition at line 396 of file quantities.h.

template<typename U, typename R = std::ratio<1>>
using util::quantities::concepts::ScaledUnit< U, R >::prefix_t = Prefix<ratio>

The prefix of the unit.

Definition at line 399 of file quantities.h.

template<typename U, typename R = std::ratio<1>>
using util::quantities::concepts::ScaledUnit< U, R >::ratio = R

The ratio to go from the base unit to this one.

Definition at line 398 of file quantities.h.

template<typename U, typename R = std::ratio<1>>
using util::quantities::concepts::ScaledUnit< U, R >::unit_t = ScaledUnit<U, R>

Unit with scale (i.e. this object).

Definition at line 397 of file quantities.h.

Member Function Documentation

template<typename U, typename R = std::ratio<1>>
static constexpr baseunit_t util::quantities::concepts::ScaledUnit< U, R >::baseUnit ( )
inlinestatic

Returns an instance of the baseunit_t type.

Definition at line 466 of file quantities.h.

466 { return {}; }
template<typename U, typename R = std::ratio<1>>
template<typename TargetRatio , typename T >
static constexpr T util::quantities::concepts::ScaledUnit< U, R >::fromRepr ( v)
inlinestatic

Converts a value from TargetRatio scale to this scaled unit.

Definition at line 449 of file quantities.h.

450  {
452  <simplified_ratio_divide<TargetRatio, ratio>>(v);
453  }
static constexpr auto applyRatioToValue(Value &&v)
Applies the specified Ratio to the value in v.
Definition: quantities.h:236
template<typename U, typename R = std::ratio<1>>
static auto util::quantities::concepts::ScaledUnit< U, R >::name ( )
inlinestatic

Returns full name of the unit (e.g. "nanoseconds") as a string-like object.

Definition at line 418 of file quantities.h.

419  { return std::string(prefix().name()) + baseUnit().name.data(); }
std::string string
Definition: nybbler.cc:12
static constexpr baseunit_t baseUnit()
Returns an instance of the baseunit_t type.
Definition: quantities.h:466
static constexpr prefix_t prefix()
Returns an instance of the prefix_t type.
Definition: quantities.h:463
template<typename U, typename R = std::ratio<1>>
static constexpr prefix_t util::quantities::concepts::ScaledUnit< U, R >::prefix ( )
inlinestatic

Returns an instance of the prefix_t type.

Definition at line 463 of file quantities.h.

463 { return {}; }
template<typename U, typename R = std::ratio<1>>
template<typename OU >
static constexpr bool util::quantities::concepts::ScaledUnit< U, R >::sameBaseUnitAs ( )
inlinestatic

Returns whether scaled unit U has the same base unit as this one.

Definition at line 473 of file quantities.h.

474  { return std::is_same<baseunit_t, typename OU::baseunit_t>(); }
template<typename U, typename R = std::ratio<1>>
template<typename OU >
static constexpr bool util::quantities::concepts::ScaledUnit< U, R >::sameUnitAs ( )
inlinestatic

Returns whether scaled unit U has the same base unit as this one.

Definition at line 478 of file quantities.h.

479  { return std::is_same<unit_t, typename OU::unit_t>(); }
template<typename U, typename R = std::ratio<1>>
template<typename T >
static constexpr T util::quantities::concepts::ScaledUnit< U, R >::scale ( v)
inlinestatic

Converts a value from the base unit to this one.

Definition at line 431 of file quantities.h.

432  { return details::applyRatioToValue<details::invert_t<ratio>>(v); }
template<typename U, typename R = std::ratio<1>>
template<typename TargetRatio , typename T >
static constexpr T util::quantities::concepts::ScaledUnit< U, R >::scaleTo ( v)
inlinestatic

Converts a value from the scaled unit to a different TargetRatio.

Definition at line 441 of file quantities.h.

442  {
444  <simplified_ratio_divide<ratio, TargetRatio>>(v);
445  }
static constexpr auto applyRatioToValue(Value &&v)
Applies the specified Ratio to the value in v.
Definition: quantities.h:236
template<typename U, typename R = std::ratio<1>>
static auto util::quantities::concepts::ScaledUnit< U, R >::symbol ( )
inlinestatic

Returns short symbol of the unit (e.g. "ns") is a string-like object.

Definition at line 413 of file quantities.h.

414  { return std::string(prefix().symbol()) + baseUnit().symbol.data(); }
std::string string
Definition: nybbler.cc:12
static auto symbol()
Returns short symbol of the unit (e.g. "ns") is a string-like object.
Definition: quantities.h:413
static constexpr baseunit_t baseUnit()
Returns an instance of the baseunit_t type.
Definition: quantities.h:466
static constexpr prefix_t prefix()
Returns an instance of the prefix_t type.
Definition: quantities.h:463
template<typename U, typename R = std::ratio<1>>
static constexpr unit_t util::quantities::concepts::ScaledUnit< U, R >::unit ( )
inlinestatic

Returns an instance of the unit_t type.

Definition at line 469 of file quantities.h.

469 { return {}; }
template<typename U, typename R = std::ratio<1>>
template<typename T >
static constexpr T util::quantities::concepts::ScaledUnit< U, R >::unscale ( v)
inlinestatic

Converts a value from this scaled unit to the base one.

Definition at line 436 of file quantities.h.

437  { return details::applyRatioToValue<ratio>(v); }

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