Library refactoring based on Walter Brown's feedback
This commit is contained in:
1 parent
2514b669c9
commit
4409fa01ca
17 files changed
+384
-346
No files matched your search
@@ -26,6 +26,8 @@
|
||||
|
||||
namespace units {
|
||||
|
||||
// todo: to be replaced with fixed_string when supported by the compilers
|
||||
|
||||
struct base_dim_length : dim_id<0> {};
|
||||
struct base_dim_mass : dim_id<1> {};
|
||||
struct base_dim_time : dim_id<2> {};
|
||||
|
||||
@@ -29,54 +29,43 @@ namespace units {
|
||||
|
||||
using dimension_frequency = make_dimension_t<exp<base_dim_time, -1>>;
|
||||
|
||||
template<typename Rep, class Ratio = std::ratio<1>>
|
||||
using frequency = quantity<dimension_frequency, Rep, Ratio>;
|
||||
using millihertz = unit<dimension_frequency, std::milli>;
|
||||
using hertz = unit<dimension_frequency, std::ratio<1>>;
|
||||
using kilohertz = unit<dimension_frequency, std::kilo>;
|
||||
using megahertz = unit<dimension_frequency, std::mega>;
|
||||
using gigahertz = unit<dimension_frequency, std::giga>;
|
||||
using terahertz = unit<dimension_frequency, std::tera>;
|
||||
|
||||
template<typename Rep>
|
||||
using millihertzs = frequency<Rep, std::milli>;
|
||||
|
||||
template<typename Rep>
|
||||
using hertzs = frequency<Rep>;
|
||||
|
||||
template<typename Rep>
|
||||
using kilohertzs = frequency<Rep, std::kilo>;
|
||||
|
||||
template<typename Rep>
|
||||
using megahertzs = frequency<Rep, std::mega>;
|
||||
|
||||
template<typename Rep>
|
||||
using gigahertzs = frequency<Rep, std::giga>;
|
||||
|
||||
template<typename Rep>
|
||||
using terahertzs = frequency<Rep, std::tera>;
|
||||
template<Unit U = hertz, typename Rep = std::intmax_t>
|
||||
using frequency = quantity<dimension_frequency, U, Rep>;
|
||||
|
||||
// ...
|
||||
|
||||
namespace literals {
|
||||
|
||||
// mHz
|
||||
constexpr auto operator""_mHz(unsigned long long l) { return millihertzs<std::int64_t>(l); }
|
||||
constexpr auto operator""_mHz(long double l) { return millihertzs<long double>(l); }
|
||||
constexpr auto operator""_mHz(unsigned long long l) { return frequency<millihertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_mHz(long double l) { return frequency<millihertz, long double>(l); }
|
||||
|
||||
// Hz
|
||||
constexpr auto operator""_Hz(unsigned long long l) { return hertzs<std::int64_t>(l); }
|
||||
constexpr auto operator""_Hz(long double l) { return hertzs<long double>(l); }
|
||||
constexpr auto operator""_Hz(unsigned long long l) { return frequency<hertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_Hz(long double l) { return frequency<hertz, long double>(l); }
|
||||
|
||||
// kHz
|
||||
constexpr auto operator""_kHz(unsigned long long l) { return kilohertzs<std::int64_t>(l); }
|
||||
constexpr auto operator""_kHz(long double l) { return kilohertzs<long double>(l); }
|
||||
constexpr auto operator""_kHz(unsigned long long l) { return frequency<kilohertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_kHz(long double l) { return frequency<kilohertz, long double>(l); }
|
||||
|
||||
// MHz
|
||||
constexpr auto operator""_MHz(unsigned long long l) { return megahertzs<std::int64_t>(l); }
|
||||
constexpr auto operator""_MHz(long double l) { return megahertzs<long double>(l); }
|
||||
constexpr auto operator""_MHz(unsigned long long l) { return frequency<megahertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_MHz(long double l) { return frequency<megahertz, long double>(l); }
|
||||
|
||||
// GHz
|
||||
constexpr auto operator""_GHz(unsigned long long l) { return gigahertzs<std::int64_t>(l); }
|
||||
constexpr auto operator""_GHz(long double l) { return gigahertzs<long double>(l); }
|
||||
constexpr auto operator""_GHz(unsigned long long l) { return frequency<gigahertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_GHz(long double l) { return frequency<gigahertz, long double>(l); }
|
||||
|
||||
// THz
|
||||
constexpr auto operator""_THz(unsigned long long l) { return terahertzs<std::int64_t>(l); }
|
||||
constexpr auto operator""_THz(long double l) { return terahertzs<long double>(l); }
|
||||
constexpr auto operator""_THz(unsigned long long l) { return frequency<terahertz, std::int64_t>(l); }
|
||||
constexpr auto operator""_THz(long double l) { return frequency<terahertz, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
@@ -29,33 +29,26 @@ namespace units {
|
||||
|
||||
using dimension_length = make_dimension_t<exp<base_dim_length, 1>>;
|
||||
|
||||
template<typename Rep, class Ratio = std::ratio<1>>
|
||||
using length = quantity<dimension_length, Rep, Ratio>;
|
||||
using millimeter = unit<dimension_length, std::milli>;
|
||||
using meter = unit<dimension_length, std::ratio<1>>;
|
||||
using kilometer = unit<dimension_length, std::kilo>;
|
||||
|
||||
template<typename Rep>
|
||||
using millimeters = length<Rep, std::milli>;
|
||||
|
||||
template<typename Rep>
|
||||
using meters = length<Rep>;
|
||||
|
||||
template<typename Rep>
|
||||
using kilometers = length<Rep, std::kilo>;
|
||||
|
||||
// ...
|
||||
template<Unit U = meter, typename Rep = std::intmax_t>
|
||||
using length = quantity<dimension_length, U, Rep>;
|
||||
|
||||
namespace literals {
|
||||
|
||||
// mm
|
||||
constexpr auto operator""_mm(unsigned long long l) { return millimeters<std::int64_t>(l); }
|
||||
constexpr auto operator""_mm(long double l) { return millimeters<long double>(l); }
|
||||
constexpr auto operator""_mm(unsigned long long l) { return length<millimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""_mm(long double l) { return length<millimeter, long double>(l); }
|
||||
|
||||
// m
|
||||
constexpr auto operator""_m(unsigned long long l) { return meters<std::int64_t>(l); }
|
||||
constexpr auto operator""_m(long double l) { return meters<long double>(l); }
|
||||
constexpr auto operator""_m(unsigned long long l) { return length<meter, std::int64_t>(l); }
|
||||
constexpr auto operator""_m(long double l) { return length<meter, long double>(l); }
|
||||
|
||||
// km
|
||||
constexpr auto operator""_km(unsigned long long l) { return kilometers<std::int64_t>(l); }
|
||||
constexpr auto operator""_km(long double l) { return kilometers<long double>(l); }
|
||||
constexpr auto operator""_km(unsigned long long l) { return length<kilometer, std::int64_t>(l); }
|
||||
constexpr auto operator""_km(long double l) { return length<kilometer, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
+20
-31
@@ -29,54 +29,43 @@ namespace units {
|
||||
|
||||
using dimension_time = make_dimension_t<exp<base_dim_time, 1>>;
|
||||
|
||||
template<typename Rep, class Ratio = std::ratio<1>>
|
||||
using time = quantity<dimension_time, Rep, Ratio>;
|
||||
using nanosecond = unit<dimension_time, std::nano>;
|
||||
using microsecond = unit<dimension_time, std::micro>;
|
||||
using millisecond = unit<dimension_time, std::milli>;
|
||||
using second = unit<dimension_time, std::ratio<1>>;
|
||||
using minute = unit<dimension_time, std::ratio<60>>;
|
||||
using hour = unit<dimension_time, std::ratio<3600>>;
|
||||
|
||||
template<typename Rep>
|
||||
using nanoseconds = time<Rep, std::nano>;
|
||||
|
||||
template<typename Rep>
|
||||
using microseconds = time<Rep, std::micro>;
|
||||
|
||||
template<typename Rep>
|
||||
using milliseconds = time<Rep, std::milli>;
|
||||
|
||||
template<typename Rep>
|
||||
using seconds = time<Rep>;
|
||||
|
||||
template<typename Rep>
|
||||
using minutes = time<Rep, std::ratio<60>>;
|
||||
|
||||
template<typename Rep>
|
||||
using hours = time<Rep, std::ratio<3600>>;
|
||||
template<Unit U = second, typename Rep = std::intmax_t>
|
||||
using time = quantity<dimension_time, U, Rep>;
|
||||
|
||||
// ...
|
||||
|
||||
namespace literals {
|
||||
|
||||
// ns
|
||||
constexpr auto operator""_ns(unsigned long long l) { return nanoseconds<std::int64_t>(l); }
|
||||
constexpr auto operator""_ns(long double l) { return nanoseconds<long double>(l); }
|
||||
constexpr auto operator""_ns(unsigned long long l) { return time<nanosecond, std::int64_t>(l); }
|
||||
constexpr auto operator""_ns(long double l) { return time<nanosecond, long double>(l); }
|
||||
|
||||
// us
|
||||
constexpr auto operator""_us(unsigned long long l) { return microseconds<std::int64_t>(l); }
|
||||
constexpr auto operator""_us(long double l) { return microseconds<long double>(l); }
|
||||
constexpr auto operator""_us(unsigned long long l) { return time<microsecond, std::int64_t>(l); }
|
||||
constexpr auto operator""_us(long double l) { return time<microsecond, long double>(l); }
|
||||
|
||||
// ms
|
||||
constexpr auto operator""_ms(unsigned long long l) { return milliseconds<std::int64_t>(l); }
|
||||
constexpr auto operator""_ms(long double l) { return milliseconds<long double>(l); }
|
||||
constexpr auto operator""_ms(unsigned long long l) { return time<millisecond, std::int64_t>(l); }
|
||||
constexpr auto operator""_ms(long double l) { return time<millisecond, long double>(l); }
|
||||
|
||||
// s
|
||||
constexpr auto operator""_s(unsigned long long l) { return seconds<std::int64_t>(l); }
|
||||
constexpr auto operator""_s(long double l) { return seconds<long double>(l); }
|
||||
constexpr auto operator""_s(unsigned long long l) { return time<second, std::int64_t>(l); }
|
||||
constexpr auto operator""_s(long double l) { return time<second, long double>(l); }
|
||||
|
||||
// min
|
||||
constexpr auto operator""_min(unsigned long long l) { return minutes<std::int64_t>(l); }
|
||||
constexpr auto operator""_min(long double l) { return minutes<long double>(l); }
|
||||
constexpr auto operator""_min(unsigned long long l) { return time<minute, std::int64_t>(l); }
|
||||
constexpr auto operator""_min(long double l) { return time<minute, long double>(l); }
|
||||
|
||||
// h
|
||||
constexpr auto operator""_h(unsigned long long l) { return hours<std::int64_t>(l); }
|
||||
constexpr auto operator""_h(long double l) { return hours<long double>(l); }
|
||||
constexpr auto operator""_h(unsigned long long l) { return time<hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_h(long double l) { return time<hour, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
@@ -30,33 +30,28 @@ namespace units {
|
||||
|
||||
using dimension_velocity = make_dimension_t<exp<base_dim_length, 1>, exp<base_dim_time, -1>>;
|
||||
|
||||
template<typename Rep, class Ratio = std::ratio<1>>
|
||||
using velocity = quantity<dimension_velocity, Rep, Ratio>;
|
||||
using meter_per_second = unit<dimension_velocity, std::ratio<1>>;
|
||||
using kilometer_per_hour = unit<dimension_velocity, std::ratio<1000, 3600>>;
|
||||
using mile_per_hour = unit<dimension_velocity, std::ratio<44'704, 100'000>>;
|
||||
|
||||
template<typename Rep>
|
||||
using meters_per_second = velocity<Rep>;
|
||||
|
||||
template<typename Rep>
|
||||
using kilometers_per_hour = velocity<Rep, std::ratio<1000, 3600>>;
|
||||
|
||||
template<typename Rep>
|
||||
using miles_per_hour = velocity<Rep, std::ratio<44'704, 100'000>>;
|
||||
template<Unit U = meter_per_second, typename Rep = std::intmax_t>
|
||||
using velocity = quantity<dimension_velocity, U, Rep>;
|
||||
|
||||
// ...
|
||||
|
||||
namespace literals {
|
||||
|
||||
// mps
|
||||
constexpr auto operator""_mps(unsigned long long l) { return meters_per_second<std::int64_t>(l); }
|
||||
constexpr auto operator""_mps(long double l) { return meters_per_second<long double>(l); }
|
||||
constexpr auto operator""_mps(unsigned long long l) { return velocity<meter_per_second, std::int64_t>(l); }
|
||||
constexpr auto operator""_mps(long double l) { return velocity<meter_per_second, long double>(l); }
|
||||
|
||||
// kmph
|
||||
constexpr auto operator""_kmph(unsigned long long l) { return kilometers_per_hour<std::int64_t>(l); }
|
||||
constexpr auto operator""_kmph(long double l) { return kilometers_per_hour<long double>(l); }
|
||||
constexpr auto operator""_kmph(unsigned long long l) { return velocity<kilometer_per_hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_kmph(long double l) { return velocity<kilometer_per_hour, long double>(l); }
|
||||
|
||||
// mph
|
||||
constexpr auto operator""_mph(unsigned long long l) { return miles_per_hour<std::int64_t>(l); }
|
||||
constexpr auto operator""_mph(long double l) { return miles_per_hour<long double>(l); }
|
||||
constexpr auto operator""_mph(unsigned long long l) { return velocity<mile_per_hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_mph(long double l) { return velocity<mile_per_hour, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
||||
Reference in new issue
Block a user