All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Namespaces | Classes
util::quantities Namespace Reference

Types of variables with a unit. More...

Namespaces

 concepts
 Infrastructure for the quantities library.
 
 datasize_literals
 Literal constants for data size quantities.
 
 details
 
 electromagnetism_literals
 Literal constants for quantities.
 
 electronics_literals
 Literal constants for electronics quantities.
 
 energy_literals
 Literal constants for energy quantities.
 
 frequency_literals
 Literal constants for frequency quantities.
 
 intervals
 
 points
 
 prefixes
 Definitions of additional prefixes.
 
 space_literals
 Literal constants for space quantities.
 
 time_literals
 Literal constants for time quantities.
 
 units
 Definitions of actual units.
 

Classes

struct  NoCategory
 
struct  MissingUnit
 String representing a quantity has no unit. More...
 
struct  InvalidUnitPrefix
 String representing a quantity has unsupported unit prefix. More...
 
struct  MismatchingUnit
 String representing a quantity has incompatible unit. More...
 
struct  ValueError
 String representing a quantity has an invalid number. More...
 
struct  ExtraCharactersError
 String representing a quantity has spurious characters after the number. More...
 

Typedefs

Data size

These time quantities are tied to util::quantities::units::Byte.

  • most general template, scaled_byte, allowing to choose both the scale of the unit (e.g. util::quantities::prefixes::mebi for mebibyte) and the type of the numerical representation
  • generic templates (e.g. byte_as), allowing to choose which numerical representation to use
  • unsigned integral number (e.g. byte), 64-bit on amd64 architecture, ready for use
template<typename R , typename T = unsigned long long int>
using scaled_byte = concepts::scaled_quantity< units::Byte, R, T >
 The most generic units::Byte-based quantity. More...
 
template<typename T = unsigned long long int>
using byte_as = scaled_byte< std::ratio< 1 >, T >
 Type of data size stored in bytes. More...
 
template<typename T = unsigned long long int>
using bytes_as = byte_as< T >
 Alias for common language habits. More...
 
using byte = byte_as<>
 Type of data size stored in bytes, in long long precision. More...
 
using bytes = byte
 Alias for common language habits. More...
 
template<typename T = unsigned long long int>
using kibibyte_as = concepts::rescale< byte_as< T >, prefixes::kibi >
 Type of data size stored in kibibytes. More...
 
template<typename T = unsigned long long int>
using kibibytes_as = kibibyte_as< T >
 Alias for common language habits. More...
 
using kibibyte = kibibyte_as<>
 Type of data size stored in kibibytes, in long long precision. More...
 
using kibibytes = kibibyte
 Alias for common language habits. More...
 
template<typename T = unsigned long long int>
using mebibyte_as = concepts::rescale< byte_as< T >, prefixes::mebi >
 Type of data size stored in mebibytes. More...
 
template<typename T = unsigned long long int>
using mebibytes_as = mebibyte_as< T >
 Alias for common language habits. More...
 
using mebibyte = mebibyte_as<>
 Type of data size stored in mebibytes, in long long precision. More...
 
using mebibytes = mebibyte
 Alias for common language habits. More...
 
template<typename T = unsigned long long int>
using gibibyte_as = concepts::rescale< byte_as< T >, prefixes::gibi >
 Type of data size stored in gibibytes. More...
 
template<typename T = unsigned long long int>
using gibibytes_as = gibibyte_as< T >
 Alias for common language habits. More...
 
using gibibyte = gibibyte_as<>
 Type of data size stored in pebibytes, in long long precision. More...
 
using gibibytes = gibibyte
 Alias for common language habits. More...
 
template<typename T = unsigned long long int>
using tebibyte_as = concepts::rescale< byte_as< T >, prefixes::tebi >
 Type of data size stored in tebibytes. More...
 
template<typename T = unsigned long long int>
using tebibytes_as = tebibyte_as< T >
 Alias for common language habits. More...
 
using tebibyte = tebibyte_as<>
 Type of data size stored in tebibytes, in long long precision. More...
 
using tebibytes = tebibyte
 Alias for common language habits. More...
 
template<typename T = unsigned long long int>
using pebibyte_as = concepts::rescale< byte_as< T >, prefixes::pebi >
 Type of data size stored in pebibytes. More...
 
template<typename T = unsigned long long int>
using pebibytes_as = pebibyte_as< T >
 Alias for common language habits. More...
 
using pebibyte = pebibyte_as<>
 Type of data size stored in pebibytes, in long long precision. More...
 
using pebibytes = pebibyte
 Alias for common language habits. More...
 
template<typename T = unsigned long long int>
using exbibyte_as = concepts::rescale< byte_as< T >, prefixes::exbi >
 Type of data size stored in exbibytes. More...
 
template<typename T = unsigned long long int>
using exbibytes_as = exbibyte_as< T >
 Alias for common language habits. More...
 
using exbibyte = exbibyte_as<>
 Type of data size stored in exbibytes, in long long precision. More...
 
using exbibytes = exbibyte
 Alias for common language habits. More...
 
Charge quantities

These charge quantities are tied to util::quantities::units::Coulomb. A few options are provided:

  • most general template, scaled_coulomb, allowing to choose both the scale of the unit (e.g. std::pico for picocoulomb) and the type of the numerical representation
  • generic templates (e.g. coulomb_as), allowing to choose which numerical representation to use
  • double precision (e.g. coulomb), ready for use
template<typename R , typename T = double>
using scaled_coulomb = concepts::scaled_quantity< units::Coulomb, R, T >
 The most generic units::Coulomb-based quantity. More...
 
template<typename T = double>
using coulomb_as = scaled_coulomb< std::ratio< 1 >, T >
 Type of charge stored in coulomb. More...
 
using coulomb = coulomb_as<>
 Type of charge stored in coulombs, in double precision. More...
 
template<typename T = double>
using millicoulomb_as = concepts::rescale< coulomb_as< T >, std::milli >
 Type of charge stored in millicoulomb. More...
 
using millicoulomb = millicoulomb_as<>
 Type of charge stored in millicoulomb, in double precision. More...
 
template<typename T = double>
using microcoulomb_as = concepts::rescale< coulomb_as< T >, std::micro >
 Type of charge stored in microcoulomb. More...
 
using microcoulomb = microcoulomb_as<>
 Type of charge stored in microcoulomb, in double precision. More...
 
template<typename T = double>
using nanocoulomb_as = concepts::rescale< coulomb_as< T >, std::nano >
 Type of charge stored in nanocoulomb. More...
 
using nanocoulomb = nanocoulomb_as<>
 Type of charge stored in nanocoulomb, in double precision. More...
 
template<typename T = double>
using picocoulomb_as = concepts::rescale< coulomb_as< T >, std::pico >
 Type of charge stored in picocoulomb. More...
 
using picocoulomb = picocoulomb_as<>
 Type of charge stored in picocoulomb, in double precision. More...
 
template<typename T = double>
using femtocoulomb_as = concepts::rescale< coulomb_as< T >, std::femto >
 Type of charge stored in femtocoulomb. More...
 
using femtocoulomb = femtocoulomb_as<>
 Type of charge stored in femtocoulomb, in double precision. More...
 
Electric potential quantities

These potential quantities are tied to util::quantities::units::Volt. A few options are provided:

  • most general template, scaled_volt, allowing to choose both the scale of the unit (e.g. std::kilo for kilovolt) and the type of the numerical representation
  • generic templates (e.g. volt_as), allowing to choose which numerical representation to use
  • double precision (e.g. volt), ready for use
template<typename R , typename T = double>
using scaled_volt = concepts::scaled_quantity< units::Volt, R, T >
 The most generic units::Volt-based quantity. More...
 
template<typename T = double>
using volt_as = scaled_volt< std::ratio< 1 >, T >
 Type of potential stored in volt. More...
 
using volt = volt_as<>
 Type of potential stored in volts, in double precision. More...
 
template<typename T = double>
using millivolt_as = concepts::rescale< volt_as< T >, std::milli >
 Type of potential stored in millivolt. More...
 
using millivolt = millivolt_as<>
 Type of potential stored in millivolt, in double precision. More...
 
template<typename T = double>
using microvolt_as = concepts::rescale< volt_as< T >, std::micro >
 Type of potential stored in microvolt. More...
 
using microvolt = microvolt_as<>
 Type of potential stored in microvolt, in double precision. More...
 
template<typename T = double>
using kilovolt_as = concepts::rescale< volt_as< T >, std::kilo >
 Type of potential stored in kilovolt. More...
 
using kilovolt = kilovolt_as<>
 Type of potential stored in kilovolt, in double precision. More...
 
template<typename T = double>
using megavolt_as = concepts::rescale< volt_as< T >, std::mega >
 Type of potential stored in megavolt. More...
 
using megavolt = megavolt_as<>
 Type of potential stored in megavolt, in double precision. More...
 
template<typename T = double>
using gigavolt_as = concepts::rescale< volt_as< T >, std::giga >
 Type of potential stored in gigavolt. More...
 
using gigavolt = gigavolt_as<>
 Type of potential stored in gigavolt, in double precision. More...
 
Ticks

These tick quantities are tied to util::quantities::units::Tick. A few options are provided:

  • generic template (tick_as), allowing to choose which numerical representation to use
  • unsigned integer (tick), based on std::ptrdiff_t, ready for use

For this unit in particular, additional options are provided to accommodate the custom of using the unit in plural form: ticks_as and ticks are exactly equivalent to the singular-named counterparts.

template<typename T = std::ptrdiff_t>
using tick_as = concepts::scaled_quantity< units::Tick, std::ratio< 1 >, T >
 Tick number, represented by the specified type T. More...
 
template<typename T = tick_as<>::value_t>
using ticks_as = tick_as< T >
 Alias for common language habits. More...
 
using tick = tick_as<>
 Tick number, represented by std::ptrdiff_t. More...
 
using ticks = tick
 Alias for common language habits. More...
 
using tick_f = tick_as< float >
 Tick number, represented by float. More...
 
using ticks_f = tick_f
 Alias for common language habits. More...
 
using tick_d = tick_as< double >
 Tick number, represented by double. More...
 
using ticks_d = tick_d
 Alias for common language habits. More...
 
ADC counts

These ADC count quantities are tied to util::quantities::units::Counts. A few options are provided:

  • generic template (counts_as), allowing to choose which numerical representation to use
  • unsigned integer (counts), based on signed short int, ready for use
template<typename T = signed short int>
using counts_as = concepts::scaled_quantity< units::Counts, std::ratio< 1 >, T >
 Number of ADC counts, represented by the specified type T. More...
 
using counts = counts_as<>
 Number of ADC counts, represented by signed short int. More...
 
using counts_f = counts_as< float >
 Number of ADC counts, represented by float. More...
 
Particle energy quantities

These energy quantities are tied to util::quantities::units::ElectronVolt. A few options are provided:

  • most general template, scaled_electronvolt, allowing to choose both the scale of the unit (e.g. std::exa for exaelectronvolt) and the type of the numerical representation
  • generic templates (e.g. electronvolt_as), allowing to choose which numerical representation to use
  • double precision (e.g. electronvolt), ready for use
template<typename R , typename T = double>
using scaled_electronvolt = concepts::scaled_quantity< units::ElectronVolt, R, T >
 The most generic units::ElectronVolt-based quantity. More...
 
template<typename T = double>
using electronvolt_as = scaled_electronvolt< std::ratio< 1 >, T >
 Type of energy stored in electronvolt. More...
 
using electronvolt = electronvolt_as<>
 Type of energy stored in electronvolts, in double precision. More...
 
template<typename T = double>
using microelectronvolt_as = concepts::rescale< electronvolt_as< T >, std::micro >
 Type of energy stored in microelectronvolt. More...
 
using microelectronvolt = microelectronvolt_as<>
 Type of energy stored in microelectronvolt, in double precision. More...
 
template<typename T = double>
using millielectronvolt_as = concepts::rescale< electronvolt_as< T >, std::milli >
 Type of energy stored in millielectronvolt. More...
 
using millielectronvolt = millielectronvolt_as<>
 Type of energy stored in millielectronvolt, in double precision. More...
 
template<typename T = double>
using kiloelectronvolt_as = concepts::rescale< electronvolt_as< T >, std::kilo >
 Type of energy stored in kiloelectronvolt. More...
 
using kiloelectronvolt = kiloelectronvolt_as<>
 Type of energy stored in kiloelectronvolt, in double precision. More...
 
template<typename T = double>
using megaelectronvolt_as = concepts::rescale< electronvolt_as< T >, std::mega >
 Type of energy stored in megaelectronvolt. More...
 
using megaelectronvolt = megaelectronvolt_as<>
 Type of energy stored in megaelectronvolt, in double precision. More...
 
template<typename T = double>
using gigaelectronvolt_as = concepts::rescale< electronvolt_as< T >, std::giga >
 Type of energy stored in gigaelectronvolt. More...
 
using gigaelectronvolt = gigaelectronvolt_as<>
 Type of energy stored in gigaelectronvolt, in double precision. More...
 
template<typename T = double>
using teraelectronvolt_as = concepts::rescale< electronvolt_as< T >, std::tera >
 Type of energy stored in teraelectronvolt. More...
 
using teraelectronvolt = teraelectronvolt_as<>
 Type of energy stored in teraelectronvolt, in double precision. More...
 
Frequency quantities

These frequency quantities are tied to util::quantities::units::Hertz. A few options are provided:

  • most general template, scaled_hertz, allowing to choose both the scale of the unit (e.g. std::kilo for kilohertz) and the type of the numerical representation
  • generic template (e.g. hertz_as), allowing to choose which numerical representation to use
  • double precision (e.g. hertz), ready for use
template<typename R , typename T = double>
using scaled_hertz = concepts::scaled_quantity< units::Hertz, R, T >
 The most generic units::Hertz-based quantity. More...
 
template<typename T = double>
using hertz_as = scaled_hertz< std::ratio< 1 >, T >
 Type of frequency stored in hertz. More...
 
using hertz = hertz_as<>
 Type of frequency stored in hertz, in double precision. More...
 
template<typename T = double>
using kilohertz_as = concepts::rescale< hertz_as< T >, std::kilo >
 Type of frequency stored in kilohertz. More...
 
using kilohertz = kilohertz_as<>
 Type of frequency stored in kilohertz, in double precision. More...
 
template<typename T = double>
using megahertz_as = concepts::rescale< hertz_as< T >, std::mega >
 Type of frequency stored in megahertz. More...
 
using megahertz = megahertz_as<>
 Type of frequency stored in megahertz, in double precision. More...
 
template<typename T = double>
using gigahertz_as = concepts::rescale< hertz_as< T >, std::giga >
 Type of frequency stored in gigahertz. More...
 
using gigahertz = gigahertz_as<>
 Type of frequency stored in gigahertz, in double precision. More...
 
Time quantities

These time quantities are tied to util::quantities::units::Second. A few options are provided:

  • most general template, scaled_second, allowing to choose both the scale of the unit (e.g. std::milli for milliseconds) and the type of the numerical representation
  • generic templates (e.g. second_as), allowing to choose which numerical representation to use
  • double precision (e.g. second), ready for use

For this unit in particular, additional options are provided to accommodate the custom of using the unit in plural form: seconds_as and seconds are exactly equivalent to the singular-named counterparts.

template<typename R , typename T = double>
using scaled_second = concepts::scaled_quantity< units::Second, R, T >
 The most generic units::Second-based quantity. More...
 
template<typename T = double>
using second_as = scaled_second< std::ratio< 1 >, T >
 Type of time stored in seconds. More...
 
template<typename T = double>
using seconds_as = second_as< T >
 Alias for common language habits. More...
 
using second = second_as<>
 Type of time stored in seconds, in double precision. More...
 
using seconds = second
 Alias for common language habits. More...
 
template<typename T = double>
using millisecond_as = concepts::rescale< second_as< T >, std::milli >
 Type of time stored in milliseconds. More...
 
template<typename T = double>
using milliseconds_as = millisecond_as< T >
 Alias for common language habits. More...
 
using millisecond = millisecond_as<>
 Type of time stored in milliseconds, in double precision. More...
 
using milliseconds = millisecond
 Alias for common language habits. More...
 
template<typename T = double>
using microsecond_as = concepts::rescale< second_as< T >, std::micro >
 Type of time stored in microseconds. More...
 
template<typename T = double>
using microseconds_as = microsecond_as< T >
 Alias for common language habits. More...
 
using microsecond = microsecond_as<>
 Type of time stored in microseconds, in double precision. More...
 
using microseconds = microsecond
 Alias for common language habits. More...
 
template<typename T = double>
using nanosecond_as = concepts::rescale< second_as< T >, std::nano >
 Type of time stored in nanoseconds. More...
 
template<typename T = double>
using nanoseconds_as = nanosecond_as< T >
 Alias for common language habits. More...
 
using nanosecond = nanosecond_as<>
 Type of time stored in nanoseconds, in double precision. More...
 
using nanoseconds = nanosecond
 Alias for common language habits. More...
 
template<typename T = double>
using picosecond_as = concepts::rescale< second_as< T >, std::pico >
 Type of time stored in picoseconds. More...
 
template<typename T = double>
using picoseconds_as = picosecond_as< T >
 Alias for common language habits. More...
 
using picosecond = picosecond_as<>
 Type of time stored in picoseconds, in double precision. More...
 
using picoseconds = picosecond
 Alias for common language habits. More...
 
Linear space quantities

These space quantities are tied to util::quantities::units::Meter. A few options are provided:

  • most general template, scaled_meter, allowing to choose both the scale of the unit (e.g. std::milli for millimeters) and the type of the numerical representation
  • generic templates (e.g. meter_as), allowing to choose which numerical representation to use
  • double precision (e.g. meter), ready for use

For this unit in particular, additional options are provided to accommodate the custom of using the unit in plural form: meters_as and meters are exactly equivalent to the singular-named counterparts.

template<typename R , typename T = double>
using scaled_meter = concepts::scaled_quantity< units::Meter, R, T >
 The most generic units::Meter-based quantity. More...
 
template<typename T = double>
using meter_as = scaled_meter< std::ratio< 1 >, T >
 Type of space stored in meters. More...
 
template<typename T = double>
using meters_as = meter_as< T >
 Alias for common language habits. More...
 
using meter = meter_as<>
 Type of space stored in meters, in double precision. More...
 
using meters = meter
 Alias for common language habits. More...
 
template<typename T = double>
using kilometer_as = concepts::rescale< meter_as< T >, std::kilo >
 Type of space stored in kilometers. More...
 
template<typename T = double>
using kilometers_as = kilometer_as< T >
 Alias for common language habits. More...
 
using kilometer = kilometer_as<>
 Type of space stored in kilometers, in double precision. More...
 
using kilometers = kilometer
 Alias for common language habits. More...
 
template<typename T = double>
using centimeter_as = concepts::rescale< meter_as< T >, std::centi >
 Type of space stored in centimeters. More...
 
template<typename T = double>
using centimeters_as = centimeter_as< T >
 Alias for common language habits. More...
 
using centimeter = centimeter_as<>
 Type of space stored in centimeters, in double precision. More...
 
using centimeters = centimeter
 Alias for common language habits. More...
 
template<typename T = double>
using millimeter_as = concepts::rescale< meter_as< T >, std::milli >
 Type of space stored in millimeters. More...
 
template<typename T = double>
using millimeters_as = millimeter_as< T >
 Alias for common language habits. More...
 
using millimeter = millimeter_as<>
 Type of space stored in millimeters, in double precision. More...
 
using millimeters = millimeter
 Alias for common language habits. More...
 
template<typename T = double>
using micrometer_as = concepts::rescale< meter_as< T >, std::micro >
 Type of space stored in micrometers. More...
 
template<typename T = double>
using micrometers_as = micrometer_as< T >
 Alias for common language habits. More...
 
using micrometer = micrometer_as<>
 Type of space stored in micrometers, in double precision. More...
 
using micrometers = micrometer
 Alias for common language habits. More...
 
template<typename T = double>
using nanometer_as = concepts::rescale< meter_as< T >, std::nano >
 Type of space stored in nanometers. More...
 
template<typename T = double>
using nanometers_as = nanometer_as< T >
 Alias for common language habits. More...
 
using nanometer = nanometer_as<>
 Type of space stored in nanometers, in double precision. More...
 
using nanometers = nanometer
 Alias for common language habits. More...
 
template<typename T = double>
using picometer_as = concepts::rescale< meter_as< T >, std::pico >
 Type of space stored in picometers. More...
 
template<typename T = double>
using picometers_as = picometer_as< T >
 Alias for common language habits. More...
 
using picometer = picometer_as<>
 Type of space stored in picometers, in double precision. More...
 
using picometers = picometer
 Alias for common language habits. More...
 
template<typename T = double>
using femtometer_as = concepts::rescale< meter_as< T >, std::femto >
 Type of space stored in femtometers. More...
 
template<typename T = double>
using femtometers_as = femtometer_as< T >
 Alias for common language habits. More...
 
using femtometer = femtometer_as<>
 Type of space stored in femtometers, in double precision. More...
 
using femtometers = femtometer
 Alias for common language habits. More...
 

Functions

template<typename IV >
IV makeInterval (std::string_view s, bool unitOptional=false)
 Returns an interval of the specified type parsed from a string. More...
 
template<typename IV >
IV makeInterval (std::string const &s, bool unitOptional=false)
 
template<typename IV >
IV makeInterval (char const *s, bool unitOptional=false)
 
template<typename PT >
PT makePoint (std::string_view s, bool unitOptional=false)
 Returns a point of the specified type parsed from a string. More...
 
template<typename PT >
PT makePoint (std::string const &s, bool unitOptional=false)
 
template<typename PT >
PT makePoint (char const *s, bool unitOptional=false)
 
template<typename Quantity >
Quantity makeQuantity (std::string_view s, bool unitOptional=false)
 Returns a quantity of the specified type parsed from a string. More...
 
template<typename Quantity >
Quantity makeQuantity (std::string const &s, bool unitOptional=false)
 
template<typename Quantity >
Quantity makeQuantity (char const *s, bool unitOptional=false)
 

Detailed Description

Types of variables with a unit.

This library uses the following concepts, vaguely inspired by Boost Units library:

Differently from Boost Units library, this one does not provide dimensional analysis (hence the lack of need for the "dimension" concept.

Usage examples

The following examples use units of time, whose definitions are actually provided elsewhere in this library (see lardataalg/Utilities/quantites/spacetime.h and the unit util::quantities::units::Second).

void drifting(double driftSpace, double driftVelocity) {
using namespace util::quantities::time_literals; // [1]
{ driftSpace / driftVelocity };
std::cout << "Drift time: " << driftTime << std::endl; // writes: "xxx us"
// double the velocity...
driftTime /= 2.0;
std::cout << "halved!! => " << driftTime << std::endl;
// add 350 ns of offset
driftTime += 0.350; // ERROR!! what is 0.350?
driftTime += 350_ns; // needs [1]; convert to microseconds and adds
std::cout << "delayed! => " << driftTime << std::endl;
// ...
auto dual = driftTime * 2.0; // dual is still `microsecond`
double half = driftTime / 2.0; // the result is converted to `double`
// and looses its unit forever
double lateTime = 500;
driftTime = lateTime; // ERROR! which unit is `lateTime` in?
driftTime = microsecond(lateTime); // assign from `lateTime` us
} // drifting()

Organization of the code

The code of this library is entirely under this namespace (util::quantities). It is organised in a few subspaces:

The file lardataalg/Utilities/quantities.h does not contain the definition of any actual quantity nor unit. Quantity libraries are expected to include this header, extend the namespace units to include the units they need, and finally adding the quantites needed directly in this very namespace.

An example of adding the definition of "ampere":

namespace util::quantities {
namespace units {
/// Unit of electric current.
struct ampere {
static constexpr auto symbol = "A"sv;
static constexpr auto name = "ampere"sv;
}; // ampere
} // namespace units
/// Type of current stored in ampere.
template <typename T = double>
using ampere_as = concepts::Quantity<concepts::ScaledUnit<units::ampere>, T>;
/// Type of current stored in ampere, in double precision.
using ampere = ampere_as<>;
/// Type of current stored in milliampere.
template <typename T = double>
using milliampere_as = concepts::rescale<ampere_as<T>, std::milli>;
/// Type of current stored in milliampere, in double precision.
using milliampere = milliampere_as<>;
} // namespace util::quantities
Note
The suffix sv converts the literal string into a std::string_view, which is one of the few string types which can be defined at compile time (constexpr) and have a decently complete interface.

Another example may be data size:

namespace util::quantities {
namespace units {
/// Unit of data size.
struct byte {
static constexpr auto symbol = "B"sv;
static constexpr auto name = "byte"sv;
}; // byte
} // namespace units
namespace binary {
// Prefix for binary 2^20 (1048576).
using mebi = std::ratio<(1U << 20), 1U>;
} // namespace binary
/// Type of data size stored bytes.
template <typename T = unsigned long long>
using byte_as = concepts::Quantity<concepts::ScaledUnit<units::byte>, T>;
/// Type of data size stored bytes, typically in 64 bits.
using byte = byte_as<>;
/// Type of data size stored in mibibyte.
template <typename T = unsigned long long>
using mebibyte_as = concepts::rescale<byte_as<T>, binary::mebi>;
/// Type of data size stored in mibibyte, typically in 64 bits.
using mebibyte = mebibyte_as<>;
} // namespace util::quantities

This example mostly works, with the following exceptions:

Typedef Documentation

using util::quantities::byte = typedef byte_as<>

Type of data size stored in bytes, in long long precision.

Definition at line 98 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::byte_as = typedef scaled_byte<std::ratio<1>, T>

Type of data size stored in bytes.

Definition at line 91 of file datasize.h.

using util::quantities::bytes = typedef byte

Alias for common language habits.

Definition at line 101 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::bytes_as = typedef byte_as<T>

Alias for common language habits.

Definition at line 95 of file datasize.h.

Type of space stored in centimeters, in double precision.

Definition at line 434 of file spacetime.h.

template<typename T = double>
using util::quantities::centimeter_as = typedef concepts::rescale<meter_as<T>, std::centi>

Type of space stored in centimeters.

Definition at line 427 of file spacetime.h.

Alias for common language habits.

Definition at line 437 of file spacetime.h.

template<typename T = double>
using util::quantities::centimeters_as = typedef centimeter_as<T>

Alias for common language habits.

Definition at line 431 of file spacetime.h.

Type of charge stored in coulombs, in double precision.

Definition at line 80 of file electromagnetism.h.

template<typename T = double>
using util::quantities::coulomb_as = typedef scaled_coulomb<std::ratio<1>, T>

Type of charge stored in coulomb.

Definition at line 77 of file electromagnetism.h.

Number of ADC counts, represented by signed short int.

Definition at line 116 of file electronics.h.

template<typename T = signed short int>
using util::quantities::counts_as = typedef concepts::scaled_quantity<units::Counts, std::ratio<1>, T>

Number of ADC counts, represented by the specified type T.

Definition at line 113 of file electronics.h.

using util::quantities::counts_f = typedef counts_as<float>

Number of ADC counts, represented by float.

Definition at line 119 of file electronics.h.

Type of energy stored in electronvolts, in double precision.

Definition at line 77 of file energy.h.

template<typename T = double>
using util::quantities::electronvolt_as = typedef scaled_electronvolt<std::ratio<1>, T>

Type of energy stored in electronvolt.

Definition at line 74 of file energy.h.

Type of data size stored in exbibytes, in long long precision.

Definition at line 200 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::exbibyte_as = typedef concepts::rescale<byte_as<T>, prefixes::exbi>

Type of data size stored in exbibytes.

Definition at line 193 of file datasize.h.

Alias for common language habits.

Definition at line 203 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::exbibytes_as = typedef exbibyte_as<T>

Alias for common language habits.

Definition at line 197 of file datasize.h.

Type of charge stored in femtocoulomb, in double precision.

Definition at line 130 of file electromagnetism.h.

template<typename T = double>
using util::quantities::femtocoulomb_as = typedef concepts::rescale<coulomb_as<T>, std::femto>

Type of charge stored in femtocoulomb.

Definition at line 127 of file electromagnetism.h.

Type of space stored in femtometers, in double precision.

Definition at line 519 of file spacetime.h.

template<typename T = double>
using util::quantities::femtometer_as = typedef concepts::rescale<meter_as<T>, std::femto>

Type of space stored in femtometers.

Definition at line 512 of file spacetime.h.

Alias for common language habits.

Definition at line 522 of file spacetime.h.

template<typename T = double>
using util::quantities::femtometers_as = typedef femtometer_as<T>

Alias for common language habits.

Definition at line 516 of file spacetime.h.

Type of data size stored in pebibytes, in long long precision.

Definition at line 149 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::gibibyte_as = typedef concepts::rescale<byte_as<T>, prefixes::gibi>

Type of data size stored in gibibytes.

Definition at line 142 of file datasize.h.

Alias for common language habits.

Definition at line 152 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::gibibytes_as = typedef gibibyte_as<T>

Alias for common language habits.

Definition at line 146 of file datasize.h.

Type of energy stored in gigaelectronvolt, in double precision.

Definition at line 129 of file energy.h.

template<typename T = double>
using util::quantities::gigaelectronvolt_as = typedef concepts::rescale<electronvolt_as<T>, std::giga>

Type of energy stored in gigaelectronvolt.

Definition at line 126 of file energy.h.

Type of frequency stored in gigahertz, in double precision.

Definition at line 111 of file frequency.h.

template<typename T = double>
using util::quantities::gigahertz_as = typedef concepts::rescale<hertz_as<T>, std::giga>

Type of frequency stored in gigahertz.

Definition at line 108 of file frequency.h.

Type of potential stored in gigavolt, in double precision.

Definition at line 216 of file electromagnetism.h.

template<typename T = double>
using util::quantities::gigavolt_as = typedef concepts::rescale<volt_as<T>, std::giga>

Type of potential stored in gigavolt.

Definition at line 213 of file electromagnetism.h.

using util::quantities::hertz = typedef hertz_as<>

Type of frequency stored in hertz, in double precision.

Definition at line 81 of file frequency.h.

template<typename T = double>
using util::quantities::hertz_as = typedef scaled_hertz<std::ratio<1>, T>

Type of frequency stored in hertz.

Definition at line 78 of file frequency.h.

Type of data size stored in kibibytes, in long long precision.

Definition at line 115 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::kibibyte_as = typedef concepts::rescale<byte_as<T>, prefixes::kibi>

Type of data size stored in kibibytes.

Definition at line 108 of file datasize.h.

Alias for common language habits.

Definition at line 118 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::kibibytes_as = typedef kibibyte_as<T>

Alias for common language habits.

Definition at line 112 of file datasize.h.

Type of energy stored in kiloelectronvolt, in double precision.

Definition at line 109 of file energy.h.

template<typename T = double>
using util::quantities::kiloelectronvolt_as = typedef concepts::rescale<electronvolt_as<T>, std::kilo>

Type of energy stored in kiloelectronvolt.

Definition at line 106 of file energy.h.

Type of frequency stored in kilohertz, in double precision.

Definition at line 91 of file frequency.h.

template<typename T = double>
using util::quantities::kilohertz_as = typedef concepts::rescale<hertz_as<T>, std::kilo>

Type of frequency stored in kilohertz.

Definition at line 88 of file frequency.h.

Type of space stored in kilometers, in double precision.

Definition at line 417 of file spacetime.h.

template<typename T = double>
using util::quantities::kilometer_as = typedef concepts::rescale<meter_as<T>, std::kilo>

Type of space stored in kilometers.

Definition at line 410 of file spacetime.h.

Alias for common language habits.

Definition at line 420 of file spacetime.h.

template<typename T = double>
using util::quantities::kilometers_as = typedef kilometer_as<T>

Alias for common language habits.

Definition at line 414 of file spacetime.h.

Type of potential stored in kilovolt, in double precision.

Definition at line 196 of file electromagnetism.h.

template<typename T = double>
using util::quantities::kilovolt_as = typedef concepts::rescale<volt_as<T>, std::kilo>

Type of potential stored in kilovolt.

Definition at line 193 of file electromagnetism.h.

Type of data size stored in mebibytes, in long long precision.

Definition at line 132 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::mebibyte_as = typedef concepts::rescale<byte_as<T>, prefixes::mebi>

Type of data size stored in mebibytes.

Definition at line 125 of file datasize.h.

Alias for common language habits.

Definition at line 135 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::mebibytes_as = typedef mebibyte_as<T>

Alias for common language habits.

Definition at line 129 of file datasize.h.

Type of energy stored in megaelectronvolt, in double precision.

Definition at line 119 of file energy.h.

template<typename T = double>
using util::quantities::megaelectronvolt_as = typedef concepts::rescale<electronvolt_as<T>, std::mega>

Type of energy stored in megaelectronvolt.

Definition at line 116 of file energy.h.

Type of frequency stored in megahertz, in double precision.

Definition at line 101 of file frequency.h.

template<typename T = double>
using util::quantities::megahertz_as = typedef concepts::rescale<hertz_as<T>, std::mega>

Type of frequency stored in megahertz.

Definition at line 98 of file frequency.h.

Type of potential stored in megavolt, in double precision.

Definition at line 206 of file electromagnetism.h.

template<typename T = double>
using util::quantities::megavolt_as = typedef concepts::rescale<volt_as<T>, std::mega>

Type of potential stored in megavolt.

Definition at line 203 of file electromagnetism.h.

using util::quantities::meter = typedef meter_as<>

Type of space stored in meters, in double precision.

Definition at line 400 of file spacetime.h.

template<typename T = double>
using util::quantities::meter_as = typedef scaled_meter<std::ratio<1>, T>

Type of space stored in meters.

Definition at line 393 of file spacetime.h.

Alias for common language habits.

Definition at line 403 of file spacetime.h.

template<typename T = double>
using util::quantities::meters_as = typedef meter_as<T>

Alias for common language habits.

Definition at line 397 of file spacetime.h.

Type of charge stored in microcoulomb, in double precision.

Definition at line 100 of file electromagnetism.h.

template<typename T = double>
using util::quantities::microcoulomb_as = typedef concepts::rescale<coulomb_as<T>, std::micro>

Type of charge stored in microcoulomb.

Definition at line 97 of file electromagnetism.h.

Type of energy stored in microelectronvolt, in double precision.

Definition at line 88 of file energy.h.

template<typename T = double>
using util::quantities::microelectronvolt_as = typedef concepts::rescale<electronvolt_as<T>, std::micro>

Type of energy stored in microelectronvolt.

Definition at line 85 of file energy.h.

Type of space stored in micrometers, in double precision.

Definition at line 468 of file spacetime.h.

template<typename T = double>
using util::quantities::micrometer_as = typedef concepts::rescale<meter_as<T>, std::micro>

Type of space stored in micrometers.

Definition at line 461 of file spacetime.h.

Alias for common language habits.

Definition at line 471 of file spacetime.h.

template<typename T = double>
using util::quantities::micrometers_as = typedef micrometer_as<T>

Alias for common language habits.

Definition at line 465 of file spacetime.h.

Type of time stored in microseconds, in double precision.

Definition at line 119 of file spacetime.h.

template<typename T = double>
using util::quantities::microsecond_as = typedef concepts::rescale<second_as<T>, std::micro>

Type of time stored in microseconds.

Definition at line 112 of file spacetime.h.

Alias for common language habits.

Definition at line 122 of file spacetime.h.

template<typename T = double>
using util::quantities::microseconds_as = typedef microsecond_as<T>

Alias for common language habits.

Definition at line 116 of file spacetime.h.

Type of potential stored in microvolt, in double precision.

Definition at line 186 of file electromagnetism.h.

template<typename T = double>
using util::quantities::microvolt_as = typedef concepts::rescale<volt_as<T>, std::micro>

Type of potential stored in microvolt.

Definition at line 183 of file electromagnetism.h.

Type of charge stored in millicoulomb, in double precision.

Definition at line 90 of file electromagnetism.h.

template<typename T = double>
using util::quantities::millicoulomb_as = typedef concepts::rescale<coulomb_as<T>, std::milli>

Type of charge stored in millicoulomb.

Definition at line 87 of file electromagnetism.h.

Type of energy stored in millielectronvolt, in double precision.

Definition at line 99 of file energy.h.

template<typename T = double>
using util::quantities::millielectronvolt_as = typedef concepts::rescale<electronvolt_as<T>, std::milli>

Type of energy stored in millielectronvolt.

Definition at line 96 of file energy.h.

Type of space stored in millimeters, in double precision.

Definition at line 451 of file spacetime.h.

template<typename T = double>
using util::quantities::millimeter_as = typedef concepts::rescale<meter_as<T>, std::milli>

Type of space stored in millimeters.

Definition at line 444 of file spacetime.h.

Alias for common language habits.

Definition at line 454 of file spacetime.h.

template<typename T = double>
using util::quantities::millimeters_as = typedef millimeter_as<T>

Alias for common language habits.

Definition at line 448 of file spacetime.h.

Type of time stored in milliseconds, in double precision.

Definition at line 102 of file spacetime.h.

template<typename T = double>
using util::quantities::millisecond_as = typedef concepts::rescale<second_as<T>, std::milli>

Type of time stored in milliseconds.

Definition at line 95 of file spacetime.h.

Alias for common language habits.

Definition at line 105 of file spacetime.h.

template<typename T = double>
using util::quantities::milliseconds_as = typedef millisecond_as<T>

Alias for common language habits.

Definition at line 99 of file spacetime.h.

Type of potential stored in millivolt, in double precision.

Definition at line 176 of file electromagnetism.h.

template<typename T = double>
using util::quantities::millivolt_as = typedef concepts::rescale<volt_as<T>, std::milli>

Type of potential stored in millivolt.

Definition at line 173 of file electromagnetism.h.

Type of charge stored in nanocoulomb, in double precision.

Definition at line 110 of file electromagnetism.h.

template<typename T = double>
using util::quantities::nanocoulomb_as = typedef concepts::rescale<coulomb_as<T>, std::nano>

Type of charge stored in nanocoulomb.

Definition at line 107 of file electromagnetism.h.

Type of space stored in nanometers, in double precision.

Definition at line 485 of file spacetime.h.

template<typename T = double>
using util::quantities::nanometer_as = typedef concepts::rescale<meter_as<T>, std::nano>

Type of space stored in nanometers.

Definition at line 478 of file spacetime.h.

Alias for common language habits.

Definition at line 488 of file spacetime.h.

template<typename T = double>
using util::quantities::nanometers_as = typedef nanometer_as<T>

Alias for common language habits.

Definition at line 482 of file spacetime.h.

Type of time stored in nanoseconds, in double precision.

Definition at line 136 of file spacetime.h.

template<typename T = double>
using util::quantities::nanosecond_as = typedef concepts::rescale<second_as<T>, std::nano>

Type of time stored in nanoseconds.

Definition at line 129 of file spacetime.h.

Alias for common language habits.

Definition at line 139 of file spacetime.h.

template<typename T = double>
using util::quantities::nanoseconds_as = typedef nanosecond_as<T>

Alias for common language habits.

Definition at line 133 of file spacetime.h.

Type of data size stored in pebibytes, in long long precision.

Definition at line 183 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::pebibyte_as = typedef concepts::rescale<byte_as<T>, prefixes::pebi>

Type of data size stored in pebibytes.

Definition at line 176 of file datasize.h.

Alias for common language habits.

Definition at line 186 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::pebibytes_as = typedef pebibyte_as<T>

Alias for common language habits.

Definition at line 180 of file datasize.h.

Type of charge stored in picocoulomb, in double precision.

Definition at line 120 of file electromagnetism.h.

template<typename T = double>
using util::quantities::picocoulomb_as = typedef concepts::rescale<coulomb_as<T>, std::pico>

Type of charge stored in picocoulomb.

Definition at line 117 of file electromagnetism.h.

Type of space stored in picometers, in double precision.

Definition at line 502 of file spacetime.h.

template<typename T = double>
using util::quantities::picometer_as = typedef concepts::rescale<meter_as<T>, std::pico>

Type of space stored in picometers.

Definition at line 495 of file spacetime.h.

Alias for common language habits.

Definition at line 505 of file spacetime.h.

template<typename T = double>
using util::quantities::picometers_as = typedef picometer_as<T>

Alias for common language habits.

Definition at line 499 of file spacetime.h.

Type of time stored in picoseconds, in double precision.

Definition at line 153 of file spacetime.h.

template<typename T = double>
using util::quantities::picosecond_as = typedef concepts::rescale<second_as<T>, std::pico>

Type of time stored in picoseconds.

Definition at line 146 of file spacetime.h.

Alias for common language habits.

Definition at line 156 of file spacetime.h.

template<typename T = double>
using util::quantities::picoseconds_as = typedef picosecond_as<T>

Alias for common language habits.

Definition at line 150 of file spacetime.h.

template<typename R , typename T = unsigned long long int>
using util::quantities::scaled_byte = typedef concepts::scaled_quantity<units::Byte, R, T>

The most generic units::Byte-based quantity.

Definition at line 84 of file datasize.h.

template<typename R , typename T = double>
using util::quantities::scaled_coulomb = typedef concepts::scaled_quantity<units::Coulomb, R, T>

The most generic units::Coulomb-based quantity.

Definition at line 70 of file electromagnetism.h.

template<typename R , typename T = double>
using util::quantities::scaled_electronvolt = typedef concepts::scaled_quantity<units::ElectronVolt, R, T>

The most generic units::ElectronVolt-based quantity.

Definition at line 67 of file energy.h.

template<typename R , typename T = double>
using util::quantities::scaled_hertz = typedef concepts::scaled_quantity<units::Hertz, R, T>

The most generic units::Hertz-based quantity.

Definition at line 71 of file frequency.h.

template<typename R , typename T = double>
using util::quantities::scaled_meter = typedef concepts::scaled_quantity<units::Meter, R, T>

The most generic units::Meter-based quantity.

Definition at line 386 of file spacetime.h.

template<typename R , typename T = double>
using util::quantities::scaled_second = typedef concepts::scaled_quantity<units::Second, R, T>

The most generic units::Second-based quantity.

Definition at line 71 of file spacetime.h.

template<typename R , typename T = double>
using util::quantities::scaled_volt = typedef concepts::scaled_quantity<units::Volt, R, T>

The most generic units::Volt-based quantity.

Definition at line 156 of file electromagnetism.h.

Type of time stored in seconds, in double precision.

Definition at line 85 of file spacetime.h.

template<typename T = double>
using util::quantities::second_as = typedef scaled_second<std::ratio<1>, T>

Type of time stored in seconds.

Definition at line 78 of file spacetime.h.

Alias for common language habits.

Definition at line 88 of file spacetime.h.

template<typename T = double>
using util::quantities::seconds_as = typedef second_as<T>

Alias for common language habits.

Definition at line 82 of file spacetime.h.

Type of data size stored in tebibytes, in long long precision.

Definition at line 166 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::tebibyte_as = typedef concepts::rescale<byte_as<T>, prefixes::tebi>

Type of data size stored in tebibytes.

Definition at line 159 of file datasize.h.

Alias for common language habits.

Definition at line 169 of file datasize.h.

template<typename T = unsigned long long int>
using util::quantities::tebibytes_as = typedef tebibyte_as<T>

Alias for common language habits.

Definition at line 163 of file datasize.h.

Type of energy stored in teraelectronvolt, in double precision.

Definition at line 139 of file energy.h.

template<typename T = double>
using util::quantities::teraelectronvolt_as = typedef concepts::rescale<electronvolt_as<T>, std::tera>

Type of energy stored in teraelectronvolt.

Definition at line 136 of file energy.h.

using util::quantities::tick = typedef tick_as<>

Tick number, represented by std::ptrdiff_t.

Definition at line 75 of file electronics.h.

template<typename T = std::ptrdiff_t>
using util::quantities::tick_as = typedef concepts::scaled_quantity<units::Tick, std::ratio<1>, T>

Tick number, represented by the specified type T.

Definition at line 68 of file electronics.h.

using util::quantities::tick_d = typedef tick_as<double>

Tick number, represented by double.

Definition at line 87 of file electronics.h.

using util::quantities::tick_f = typedef tick_as<float>

Tick number, represented by float.

Definition at line 81 of file electronics.h.

using util::quantities::ticks = typedef tick

Alias for common language habits.

Definition at line 78 of file electronics.h.

template<typename T = tick_as<>::value_t>
using util::quantities::ticks_as = typedef tick_as<T>

Alias for common language habits.

Definition at line 72 of file electronics.h.

Alias for common language habits.

Definition at line 90 of file electronics.h.

Alias for common language habits.

Definition at line 84 of file electronics.h.

using util::quantities::volt = typedef volt_as<>

Type of potential stored in volts, in double precision.

Definition at line 166 of file electromagnetism.h.

template<typename T = double>
using util::quantities::volt_as = typedef scaled_volt<std::ratio<1>, T>

Type of potential stored in volt.

Definition at line 163 of file electromagnetism.h.

Function Documentation

template<typename IV >
IV util::quantities::makeInterval ( std::string_view  s,
bool  unitOptional = false 
)

Returns an interval of the specified type parsed from a string.

Template Parameters
IVthe type of quantity interval to be returned
Parameters
sthe string to be parsed
unitOptional(default: false) whether unit is not required in s
Returns
a quantity interval of the specified type parsed from a string
Exceptions
MissingUnits does not contain the required unit
ValueErrorthe numerical value in s is not parseable
ExtraCharactersErrorspurious characters after the numeric value
See Also
util::makeQuantity()

This function behaves like util::makeQuantity().

Definition at line 1205 of file intervals.h.

1206 {
1207  using quantity_t = typename IV::quantity_t;
1208  return { util::quantities::makeQuantity<quantity_t>(s, unitOptional) };
1209 } // util::quantities::makeInterval(string_view)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
template<typename IV >
IV util::quantities::makeInterval ( std::string const &  s,
bool  unitOptional = false 
)

Definition at line 1215 of file intervals.h.

1216 {
1217  using quantity_t = typename IV::quantity_t;
1218  return { util::quantities::makeQuantity<quantity_t>(s, unitOptional) };
1219 } // util::quantities::makeInterval(string)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
template<typename IV >
IV util::quantities::makeInterval ( char const *  s,
bool  unitOptional = false 
)

Definition at line 1225 of file intervals.h.

1226 {
1227  using quantity_t = typename IV::quantity_t;
1228  return { util::quantities::makeQuantity<quantity_t>(s, unitOptional) };
1229 } // util::quantities::makeInterval(C-string)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
template<typename PT >
PT util::quantities::makePoint ( std::string_view  s,
bool  unitOptional = false 
)

Returns a point of the specified type parsed from a string.

Template Parameters
PTthe type of quantity point to be returned
Parameters
sthe string to be parsed
unitOptional(default: false) whether unit is not required in s
Returns
a quantity point of the specified type parsed from a string
Exceptions
MissingUnits does not contain the required unit
ValueErrorthe numerical value in s is not parseable
ExtraCharactersErrorspurious characters after the numeric value
See Also
util::makeQuantity()

This function behaves like util::makeQuantity().

Definition at line 1235 of file intervals.h.

1236 {
1237  using quantity_t = typename PT::quantity_t;
1238  return { util::quantities::makeQuantity<quantity_t>(s, unitOptional) };
1239 } // util::quantities::makePoint(string_view)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
template<typename PT >
PT util::quantities::makePoint ( std::string const &  s,
bool  unitOptional = false 
)

Definition at line 1245 of file intervals.h.

1246 {
1247  using quantity_t = typename PT::quantity_t;
1248  return { util::quantities::makeQuantity<quantity_t>(s, unitOptional) };
1249 } // util::quantities::makePoint(string)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
template<typename PT >
PT util::quantities::makePoint ( char const *  s,
bool  unitOptional = false 
)

Definition at line 1255 of file intervals.h.

1256 {
1257  using quantity_t = typename PT::quantity_t;
1258  return { util::quantities::makeQuantity<quantity_t>(s, unitOptional) };
1259 } // util::quantities::makePoint(C-string)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
template<typename Quantity >
Quantity util::quantities::makeQuantity ( std::string_view  s,
bool  unitOptional = false 
)

Returns a quantity of the specified type parsed from a string.

Template Parameters
Quantitythe quantity to be returned
Parameters
sthe string to be parsed
unitOptional(default: false) whether unit is not required in s
Returns
a quantity of the specified type parsed from a string
Exceptions
MissingUnits does not contain the required unit
ValueErrorthe numerical value in s is not parseable
ExtraCharactersErrorspurious characters after the numeric value (including an unrecognised unit prefix)

A quantity of type Quantity is returned, whose value is interpreted from the content of s. The standard format includes a real number, a space and a unit symbol. If unitOptional is false, that unit is required, otherwise it is optional and defaults to the unit and scale in Quantity. The base unit in s, when present, must exactly match the base unit of Quantity; the scale may differ, in which case the proper conversion is applied.

Example:

using namespace util::quantities::time_literals;
auto const t = util::quantities::makeQuantity<microsecond>("7 ms");

will assign to t the value 7000.

Definition at line 1690 of file quantities.h.

1691 {
1692  return util::quantities::makeQuantity<Quantity>
1693  (std::string{ s.begin(), s.end() }, unitOptional);
1694 } // util::quantities::makeQuantity(string_view)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
template<typename Quantity >
Quantity util::quantities::makeQuantity ( std::string const &  s,
bool  unitOptional = false 
)

Definition at line 1653 of file quantities.h.

1654 {
1655  //
1656  // all this function is horrible;
1657  // some redesign is needed...
1658  //
1659  using value_t = typename Quantity::value_t;
1660 
1661  auto const [ num_s, factor ] = details::readUnit<Quantity>(s, unitOptional);
1662 
1663  char* parseEnd = nullptr;
1664  auto const value
1665  = static_cast<value_t>(std::strtod(num_s.c_str(), &parseEnd));
1666  const char* send = num_s.c_str() + num_s.length();
1667  if (parseEnd == num_s.c_str()) {
1668  throw ValueError("Could not convert '" + num_s + "' into a number!");
1669  }
1670  while (parseEnd != send) {
1671  if (!std::isblank(static_cast<unsigned char>(*parseEnd))) {
1672  throw ExtraCharactersError("Spurious characters after value "
1673  + std::to_string(value) + " in '" + num_s + "' ('"
1674  + std::string(parseEnd, send - parseEnd) + "')\n"
1675  );
1676  }
1677  ++parseEnd;
1678  } // while
1679 
1680  //
1681  // create and return the quantity
1682  //
1683  return Quantity{ static_cast<value_t>(value * factor) };
1684 } // util::quantities::makeQuantity(string_view)
value_t
the JSON type enumeration
Definition: json.hpp:2854
std::string to_string(WindowPattern const &pattern)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
temporary value
template<typename Quantity >
Quantity util::quantities::makeQuantity ( char const *  s,
bool  unitOptional = false 
)

Definition at line 1700 of file quantities.h.

1701 {
1702  return
1703  util::quantities::makeQuantity<Quantity>(std::string_view{s}, unitOptional);
1704 } // util::quantities::makeQuantity(string)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60