mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 19:04:27 +02:00
meter renamed to metre
This commit is contained in:
@@ -50,8 +50,8 @@ point of view the most important is a quantity.
|
||||
Quantity is a concrete amount of a unit for a specified dimension with a specific representation:
|
||||
|
||||
```cpp
|
||||
units::quantity<units::kilometer, double> d1(123);
|
||||
auto d2 = 123km; // stde::units::quantity<units::kilometer, std::int64_t>
|
||||
units::quantity<units::kilometre, double> d1(123);
|
||||
auto d2 = 123km; // stde::units::quantity<units::kilometre, std::int64_t>
|
||||
```
|
||||
|
||||
There are C++ concepts provided for each such quantity type:
|
||||
@@ -418,8 +418,8 @@ template<> struct downcasting_traits<downcast_from<dimension_length>> : downcast
|
||||
```
|
||||
|
||||
```cpp
|
||||
struct kilometer : unit<dimension_length, std::kilo> {};
|
||||
template<> struct downcasting_traits<downcast_from<kilometer>> : downcast_to<kilometer> {};
|
||||
struct kilometre : unit<dimension_length, std::kilo> {};
|
||||
template<> struct downcasting_traits<downcast_from<kilometre>> : downcast_to<kilometre> {};
|
||||
```
|
||||
|
||||
|
||||
@@ -446,33 +446,33 @@ concept Velocity = Quantity<T> && std::Same<typename T::dimension, dimension_vel
|
||||
- base unit
|
||||
|
||||
```cpp
|
||||
struct meter : unit<dimension_length, std::ratio<1>> {};
|
||||
template<> struct downcasting_traits<downcast_from<meter>> : downcast_to<meter> {};
|
||||
struct metre : unit<dimension_length, std::ratio<1>> {};
|
||||
template<> struct downcasting_traits<downcast_from<metre>> : downcast_to<metre> {};
|
||||
```
|
||||
|
||||
- units with prefixes
|
||||
|
||||
```cpp
|
||||
struct kilometer : kilo<meter> {};
|
||||
template<> struct downcasting_traits<downcast_from<kilometer>> : downcast_to<kilometer> {};
|
||||
struct kilometre : kilo<metre> {};
|
||||
template<> struct downcasting_traits<downcast_from<kilometre>> : downcast_to<kilometre> {};
|
||||
```
|
||||
|
||||
- derived units
|
||||
|
||||
```cpp
|
||||
struct kilometer_per_hour : derived_unit<dimension_velocity, kilometer, hour> {};
|
||||
template<> struct downcasting_traits<downcast_from<kilometer_per_hour>> : downcast_to<kilometer_per_hour> {};
|
||||
struct kilometre_per_hour : derived_unit<dimension_velocity, kilometre, hour> {};
|
||||
template<> struct downcasting_traits<downcast_from<kilometre_per_hour>> : downcast_to<kilometre_per_hour> {};
|
||||
```
|
||||
|
||||
5. Provide user-defined literals for the most important units:
|
||||
|
||||
```cpp
|
||||
inline namespace literals {
|
||||
constexpr auto operator""_mps(unsigned long long l) { return quantity<meter_per_second, std::int64_t>(l); }
|
||||
constexpr auto operator""_mps(long double l) { return quantity<meter_per_second, long double>(l); }
|
||||
constexpr auto operator""_mps(unsigned long long l) { return quantity<metre_per_second, std::int64_t>(l); }
|
||||
constexpr auto operator""_mps(long double l) { return quantity<metre_per_second, long double>(l); }
|
||||
|
||||
constexpr auto operator""_kmph(unsigned long long l) { return quantity<kilometer_per_hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_kmph(long double l) { return quantity<kilometer_per_hour, long double>(l); }
|
||||
constexpr auto operator""_kmph(unsigned long long l) { return quantity<kilometre_per_hour, std::int64_t>(l); }
|
||||
constexpr auto operator""_kmph(long double l) { return quantity<kilometre_per_hour, long double>(l); }
|
||||
}
|
||||
```
|
||||
|
||||
|
@@ -39,12 +39,12 @@ void example_1(V v, T t)
|
||||
{
|
||||
const stde::units::Length distance = v * t;
|
||||
std::cout << "A car driving " << v.count() << " km/h in a time of " << t.count() << " minutes will pass "
|
||||
<< stde::units::quantity_cast<stde::units::quantity<stde::units::meter, double>>(distance).count() << " meters.\n";
|
||||
<< stde::units::quantity_cast<stde::units::quantity<stde::units::metre, double>>(distance).count() << " metres.\n";
|
||||
}
|
||||
|
||||
void example_2(double distance_v, double duration_v)
|
||||
{
|
||||
stde::units::quantity<stde::units::kilometer> distance(distance_v);
|
||||
stde::units::quantity<stde::units::kilometre> distance(distance_v);
|
||||
stde::units::quantity<stde::units::hour> duration(duration_v);
|
||||
const auto kmph = avg_speed(distance, duration);
|
||||
std::cout << "Average speed of a car that makes " << distance.count() << " km in "
|
||||
|
@@ -32,14 +32,14 @@ namespace std::experimental::units {
|
||||
template<typename T>
|
||||
concept bool Acceleration = Quantity<T> && std::Same<typename T::dimension, dimension_acceleration>;
|
||||
|
||||
struct meter_per_second_sq : derived_unit<dimension_acceleration, meter, second> {};
|
||||
template<> struct downcasting_traits<downcast_from<meter_per_second_sq>> : downcast_to<meter_per_second_sq> {};
|
||||
struct metre_per_second_sq : derived_unit<dimension_acceleration, metre, second> {};
|
||||
template<> struct downcasting_traits<downcast_from<metre_per_second_sq>> : downcast_to<metre_per_second_sq> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// mps_sq
|
||||
constexpr auto operator""mps_sq(unsigned long long l) { return quantity<meter_per_second_sq, std::int64_t>(l); }
|
||||
constexpr auto operator""mps_sq(long double l) { return quantity<meter_per_second_sq, long double>(l); }
|
||||
constexpr auto operator""mps_sq(unsigned long long l) { return quantity<metre_per_second_sq, std::int64_t>(l); }
|
||||
constexpr auto operator""mps_sq(long double l) { return quantity<metre_per_second_sq, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
@@ -32,17 +32,17 @@ namespace std::experimental::units {
|
||||
template<typename T>
|
||||
concept bool Area = Quantity<T> && std::Same<typename T::dimension, dimension_area>;
|
||||
|
||||
struct square_millimeter : derived_unit<dimension_area, millimeter> {};
|
||||
template<> struct downcasting_traits<downcast_from<square_millimeter>> : downcast_to<square_millimeter> {};
|
||||
struct square_millimetre : derived_unit<dimension_area, millimetre> {};
|
||||
template<> struct downcasting_traits<downcast_from<square_millimetre>> : downcast_to<square_millimetre> {};
|
||||
|
||||
struct square_centimeter : derived_unit<dimension_area, centimeter> {};
|
||||
template<> struct downcasting_traits<downcast_from<square_centimeter>> : downcast_to<square_centimeter> {};
|
||||
struct square_centimetre : derived_unit<dimension_area, centimetre> {};
|
||||
template<> struct downcasting_traits<downcast_from<square_centimetre>> : downcast_to<square_centimetre> {};
|
||||
|
||||
struct square_meter : derived_unit<dimension_area, meter> {};
|
||||
template<> struct downcasting_traits<downcast_from<square_meter>> : downcast_to<square_meter> {};
|
||||
struct square_metre : derived_unit<dimension_area, metre> {};
|
||||
template<> struct downcasting_traits<downcast_from<square_metre>> : downcast_to<square_metre> {};
|
||||
|
||||
struct square_kilometer : derived_unit<dimension_area, kilometer, meter> {};
|
||||
template<> struct downcasting_traits<downcast_from<square_kilometer>> : downcast_to<square_kilometer> {};
|
||||
struct square_kilometre : derived_unit<dimension_area, kilometre, metre> {};
|
||||
template<> struct downcasting_traits<downcast_from<square_kilometre>> : downcast_to<square_kilometre> {};
|
||||
|
||||
struct square_foot : derived_unit<dimension_area, foot> {};
|
||||
template<> struct downcasting_traits<downcast_from<square_foot>> : downcast_to<square_foot> {};
|
||||
@@ -50,20 +50,20 @@ namespace std::experimental::units {
|
||||
inline namespace literals {
|
||||
|
||||
// sq_mm
|
||||
constexpr auto operator""sq_mm(unsigned long long l) { return quantity<square_millimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""sq_mm(long double l) { return quantity<square_millimeter, long double>(l); }
|
||||
constexpr auto operator""sq_mm(unsigned long long l) { return quantity<square_millimetre, std::int64_t>(l); }
|
||||
constexpr auto operator""sq_mm(long double l) { return quantity<square_millimetre, long double>(l); }
|
||||
|
||||
// sq_cm
|
||||
constexpr auto operator""sq_cm(unsigned long long l) { return quantity<square_centimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""sq_cm(long double l) { return quantity<square_centimeter, long double>(l); }
|
||||
constexpr auto operator""sq_cm(unsigned long long l) { return quantity<square_centimetre, std::int64_t>(l); }
|
||||
constexpr auto operator""sq_cm(long double l) { return quantity<square_centimetre, long double>(l); }
|
||||
|
||||
// sq_m
|
||||
constexpr auto operator""sq_m(unsigned long long l) { return quantity<square_meter, std::int64_t>(l); }
|
||||
constexpr auto operator""sq_m(long double l) { return quantity<square_meter, long double>(l); }
|
||||
constexpr auto operator""sq_m(unsigned long long l) { return quantity<square_metre, std::int64_t>(l); }
|
||||
constexpr auto operator""sq_m(long double l) { return quantity<square_metre, long double>(l); }
|
||||
|
||||
// sq_km
|
||||
constexpr auto operator""sq_km(unsigned long long l) { return quantity<square_kilometer, std::int64_t>(l); }
|
||||
constexpr auto operator""sq_km(long double l) { return quantity<square_kilometer, long double>(l); }
|
||||
constexpr auto operator""sq_km(unsigned long long l) { return quantity<square_kilometre, std::int64_t>(l); }
|
||||
constexpr auto operator""sq_km(long double l) { return quantity<square_kilometre, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
@@ -34,7 +34,7 @@ namespace std::experimental::units {
|
||||
template<typename T>
|
||||
concept bool Capacitance = Quantity<T> && std::Same<typename T::dimension, dimension_capacitance>;
|
||||
|
||||
struct farad : derived_unit<dimension_capacitance, kilogram, meter, second, ampere> {};
|
||||
struct farad : derived_unit<dimension_capacitance, kilogram, metre, second, ampere> {};
|
||||
template<> struct downcasting_traits<downcast_from<farad>> : downcast_to<farad> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
@@ -34,7 +34,7 @@ namespace std::experimental::units {
|
||||
template<typename T>
|
||||
concept bool Energy = Quantity<T> && std::Same<typename T::dimension, dimension_energy>;
|
||||
|
||||
struct joule : derived_unit<dimension_energy, kilogram, meter, second> {};
|
||||
struct joule : derived_unit<dimension_energy, kilogram, metre, second> {};
|
||||
template<> struct downcasting_traits<downcast_from<joule>> : downcast_to<joule> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
@@ -35,7 +35,7 @@ namespace std::experimental::units {
|
||||
template<typename T>
|
||||
concept bool Force = Quantity<T> && std::Same<typename T::dimension, dimension_force>;
|
||||
|
||||
struct newton : derived_unit<dimension_force, kilogram, meter, second> {};
|
||||
struct newton : derived_unit<dimension_force, kilogram, metre, second> {};
|
||||
template<> struct downcasting_traits<downcast_from<newton>> : downcast_to<newton> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
@@ -34,35 +34,35 @@ namespace std::experimental::units {
|
||||
concept bool Length = Quantity<T> && std::Same<typename T::dimension, dimension_length>;
|
||||
|
||||
// SI units
|
||||
struct meter : unit<dimension_length> {};
|
||||
template<> struct downcasting_traits<downcast_from<meter>> : downcast_to<meter> {};
|
||||
struct metre : unit<dimension_length> {};
|
||||
template<> struct downcasting_traits<downcast_from<metre>> : downcast_to<metre> {};
|
||||
|
||||
struct millimeter : milli<meter> {};
|
||||
template<> struct downcasting_traits<downcast_from<millimeter>> : downcast_to<millimeter> {};
|
||||
struct millimetre : milli<metre> {};
|
||||
template<> struct downcasting_traits<downcast_from<millimetre>> : downcast_to<millimetre> {};
|
||||
|
||||
struct centimeter : centi<meter> {};
|
||||
template<> struct downcasting_traits<downcast_from<centimeter>> : downcast_to<centimeter> {};
|
||||
struct centimetre : centi<metre> {};
|
||||
template<> struct downcasting_traits<downcast_from<centimetre>> : downcast_to<centimetre> {};
|
||||
|
||||
struct kilometer : kilo<meter> {};
|
||||
template<> struct downcasting_traits<downcast_from<kilometer>> : downcast_to<kilometer> {};
|
||||
struct kilometre : kilo<metre> {};
|
||||
template<> struct downcasting_traits<downcast_from<kilometre>> : downcast_to<kilometre> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// mm
|
||||
constexpr auto operator""mm(unsigned long long l) { return quantity<millimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""mm(long double l) { return quantity<millimeter, long double>(l); }
|
||||
constexpr auto operator""mm(unsigned long long l) { return quantity<millimetre, std::int64_t>(l); }
|
||||
constexpr auto operator""mm(long double l) { return quantity<millimetre, long double>(l); }
|
||||
|
||||
// cm
|
||||
constexpr auto operator""cm(unsigned long long l) { return quantity<centimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""cm(long double l) { return quantity<centimeter, long double>(l); }
|
||||
constexpr auto operator""cm(unsigned long long l) { return quantity<centimetre, std::int64_t>(l); }
|
||||
constexpr auto operator""cm(long double l) { return quantity<centimetre, long double>(l); }
|
||||
|
||||
// m
|
||||
constexpr auto operator""m(unsigned long long l) { return quantity<meter, std::int64_t>(l); }
|
||||
constexpr auto operator""m(long double l) { return quantity<meter, long double>(l); }
|
||||
constexpr auto operator""m(unsigned long long l) { return quantity<metre, std::int64_t>(l); }
|
||||
constexpr auto operator""m(long double l) { return quantity<metre, long double>(l); }
|
||||
|
||||
// km
|
||||
constexpr auto operator""km(unsigned long long l) { return quantity<kilometer, std::int64_t>(l); }
|
||||
constexpr auto operator""km(long double l) { return quantity<kilometer, long double>(l); }
|
||||
constexpr auto operator""km(unsigned long long l) { return quantity<kilometre, std::int64_t>(l); }
|
||||
constexpr auto operator""km(long double l) { return quantity<kilometre, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
@@ -33,7 +33,7 @@ namespace std::experimental::units {
|
||||
template<typename T>
|
||||
concept bool Power = Quantity<T> && std::Same<typename T::dimension, dimension_power>;
|
||||
|
||||
struct watt : derived_unit<dimension_power, kilogram, meter, second> {};
|
||||
struct watt : derived_unit<dimension_power, kilogram, metre, second> {};
|
||||
template<> struct downcasting_traits<downcast_from<watt>> : downcast_to<watt> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
@@ -33,7 +33,7 @@ namespace std::experimental::units {
|
||||
template<typename T>
|
||||
concept bool Pressure = Quantity<T> && std::Same<typename T::dimension, dimension_pressure>;
|
||||
|
||||
struct pascal : derived_unit<dimension_pressure, kilogram, meter, second> {};
|
||||
struct pascal : derived_unit<dimension_pressure, kilogram, metre, second> {};
|
||||
template<> struct downcasting_traits<downcast_from<pascal>> : downcast_to<pascal> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
@@ -33,11 +33,11 @@ namespace std::experimental::units {
|
||||
template<typename T>
|
||||
concept bool Velocity = Quantity<T> && std::Same<typename T::dimension, dimension_velocity>;
|
||||
|
||||
struct meter_per_second : derived_unit<dimension_velocity, meter, second> {};
|
||||
template<> struct downcasting_traits<downcast_from<meter_per_second>> : downcast_to<meter_per_second> {};
|
||||
struct metre_per_second : derived_unit<dimension_velocity, metre, second> {};
|
||||
template<> struct downcasting_traits<downcast_from<metre_per_second>> : downcast_to<metre_per_second> {};
|
||||
|
||||
struct kilometer_per_hour : derived_unit<dimension_velocity, kilometer, hour> {};
|
||||
template<> struct downcasting_traits<downcast_from<kilometer_per_hour>> : downcast_to<kilometer_per_hour> {};
|
||||
struct kilometre_per_hour : derived_unit<dimension_velocity, kilometre, hour> {};
|
||||
template<> struct downcasting_traits<downcast_from<kilometre_per_hour>> : downcast_to<kilometre_per_hour> {};
|
||||
|
||||
struct mile_per_hour : derived_unit<dimension_velocity, mile, hour> {};
|
||||
template<> struct downcasting_traits<downcast_from<mile_per_hour>> : downcast_to<mile_per_hour> {};
|
||||
@@ -45,12 +45,12 @@ namespace std::experimental::units {
|
||||
inline namespace literals {
|
||||
|
||||
// mps
|
||||
constexpr auto operator""mps(unsigned long long l) { return quantity<meter_per_second, std::int64_t>(l); }
|
||||
constexpr auto operator""mps(long double l) { return quantity<meter_per_second, long double>(l); }
|
||||
constexpr auto operator""mps(unsigned long long l) { return quantity<metre_per_second, std::int64_t>(l); }
|
||||
constexpr auto operator""mps(long double l) { return quantity<metre_per_second, long double>(l); }
|
||||
|
||||
// kmph
|
||||
constexpr auto operator""kmph(unsigned long long l) { return quantity<kilometer_per_hour, std::int64_t>(l); }
|
||||
constexpr auto operator""kmph(long double l) { return quantity<kilometer_per_hour, long double>(l); }
|
||||
constexpr auto operator""kmph(unsigned long long l) { return quantity<kilometre_per_hour, std::int64_t>(l); }
|
||||
constexpr auto operator""kmph(long double l) { return quantity<kilometre_per_hour, long double>(l); }
|
||||
|
||||
// mph
|
||||
constexpr auto operator""mph(unsigned long long l) { return quantity<mile_per_hour, std::int64_t>(l); }
|
||||
|
@@ -36,7 +36,7 @@ namespace std::experimental::units {
|
||||
template<typename T>
|
||||
concept bool Voltage = Quantity<T> && std::Same<typename T::dimension, dimension_voltage>;
|
||||
|
||||
struct volt : derived_unit<dimension_voltage, kilogram, meter, second, ampere> {};
|
||||
struct volt : derived_unit<dimension_voltage, kilogram, metre, second, ampere> {};
|
||||
template<> struct downcasting_traits<downcast_from<volt>> : downcast_to<volt> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
@@ -32,17 +32,17 @@ namespace std::experimental::units {
|
||||
template<typename T>
|
||||
concept bool Volume = Quantity<T> && std::Same<typename T::dimension, dimension_volume>;
|
||||
|
||||
struct cubic_millimeter : derived_unit<dimension_volume, millimeter> {};
|
||||
template<> struct downcasting_traits<downcast_from<cubic_millimeter>> : downcast_to<cubic_millimeter> {};
|
||||
struct cubic_millimetre : derived_unit<dimension_volume, millimetre> {};
|
||||
template<> struct downcasting_traits<downcast_from<cubic_millimetre>> : downcast_to<cubic_millimetre> {};
|
||||
|
||||
struct cubic_centimeter : derived_unit<dimension_volume, centimeter> {};
|
||||
template<> struct downcasting_traits<downcast_from<cubic_centimeter>> : downcast_to<cubic_centimeter> {};
|
||||
struct cubic_centimetre : derived_unit<dimension_volume, centimetre> {};
|
||||
template<> struct downcasting_traits<downcast_from<cubic_centimetre>> : downcast_to<cubic_centimetre> {};
|
||||
|
||||
struct cubic_meter : derived_unit<dimension_volume, meter> {};
|
||||
template<> struct downcasting_traits<downcast_from<cubic_meter>> : downcast_to<cubic_meter> {};
|
||||
struct cubic_metre : derived_unit<dimension_volume, metre> {};
|
||||
template<> struct downcasting_traits<downcast_from<cubic_metre>> : downcast_to<cubic_metre> {};
|
||||
|
||||
struct cubic_kilometer : derived_unit<dimension_volume, kilometer, meter> {};
|
||||
template<> struct downcasting_traits<downcast_from<cubic_kilometer>> : downcast_to<cubic_kilometer> {};
|
||||
struct cubic_kilometre : derived_unit<dimension_volume, kilometre, metre> {};
|
||||
template<> struct downcasting_traits<downcast_from<cubic_kilometre>> : downcast_to<cubic_kilometre> {};
|
||||
|
||||
struct cubic_foot : derived_unit<dimension_volume, foot> {};
|
||||
template<> struct downcasting_traits<downcast_from<cubic_foot>> : downcast_to<cubic_foot> {};
|
||||
@@ -50,20 +50,20 @@ namespace std::experimental::units {
|
||||
inline namespace literals {
|
||||
|
||||
// cub_mm
|
||||
constexpr auto operator""cub_mm(unsigned long long l) { return quantity<cubic_millimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""cub_mm(long double l) { return quantity<cubic_millimeter, long double>(l); }
|
||||
constexpr auto operator""cub_mm(unsigned long long l) { return quantity<cubic_millimetre, std::int64_t>(l); }
|
||||
constexpr auto operator""cub_mm(long double l) { return quantity<cubic_millimetre, long double>(l); }
|
||||
|
||||
// cub_cm
|
||||
constexpr auto operator""cub_cm(unsigned long long l) { return quantity<cubic_centimeter, std::int64_t>(l); }
|
||||
constexpr auto operator""cub_cm(long double l) { return quantity<cubic_centimeter, long double>(l); }
|
||||
constexpr auto operator""cub_cm(unsigned long long l) { return quantity<cubic_centimetre, std::int64_t>(l); }
|
||||
constexpr auto operator""cub_cm(long double l) { return quantity<cubic_centimetre, long double>(l); }
|
||||
|
||||
// cub_m
|
||||
constexpr auto operator""cub_m(unsigned long long l) { return quantity<cubic_meter, std::int64_t>(l); }
|
||||
constexpr auto operator""cub_m(long double l) { return quantity<cubic_meter, long double>(l); }
|
||||
constexpr auto operator""cub_m(unsigned long long l) { return quantity<cubic_metre, std::int64_t>(l); }
|
||||
constexpr auto operator""cub_m(long double l) { return quantity<cubic_metre, long double>(l); }
|
||||
|
||||
// cub_km
|
||||
constexpr auto operator""cub_km(unsigned long long l) { return quantity<cubic_kilometer, std::int64_t>(l); }
|
||||
constexpr auto operator""cub_km(long double l) { return quantity<cubic_kilometer, long double>(l); }
|
||||
constexpr auto operator""cub_km(unsigned long long l) { return quantity<cubic_kilometre, std::int64_t>(l); }
|
||||
constexpr auto operator""cub_km(long double l) { return quantity<cubic_kilometre, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
|
@@ -77,76 +77,76 @@ namespace {
|
||||
// class invariants
|
||||
|
||||
// constexpr quantity<dimension_length, second, int> q; // should a static_assert
|
||||
// constexpr quantity<dimension_length, meter, quantity<meter, int>> error(0m); // should trigger a static_assert
|
||||
// constexpr quantity<dimension_length, metre, quantity<metre, int>> error(0m); // should trigger a static_assert
|
||||
// constexpr quantity<int, int, double> error(0); // should trigger a static_assert
|
||||
// constexpr quantity<dimension_length, unit<dimension_length, std::ratio<-1, 1>>, int> error(0); // should trigger a static_assert
|
||||
|
||||
// member types
|
||||
|
||||
static_assert(std::is_same_v<quantity<meter, int>::rep, int>);
|
||||
static_assert(std::is_same_v<quantity<meter, double>::rep, double>);
|
||||
static_assert(std::is_same_v<quantity<meter, int>::unit, meter>);
|
||||
static_assert(std::is_same_v<quantity<kilometer, int>::unit, kilometer>);
|
||||
static_assert(std::is_same_v<quantity<metre, int>::rep, int>);
|
||||
static_assert(std::is_same_v<quantity<metre, double>::rep, double>);
|
||||
static_assert(std::is_same_v<quantity<metre, int>::unit, metre>);
|
||||
static_assert(std::is_same_v<quantity<kilometre, int>::unit, kilometre>);
|
||||
|
||||
// constructors
|
||||
|
||||
static_assert(quantity<meter, int>().count() == 0);
|
||||
constexpr quantity<meter, int> km{1000};
|
||||
static_assert(quantity<metre, int>().count() == 0);
|
||||
constexpr quantity<metre, int> km{1000};
|
||||
static_assert(km.count() == 1000);
|
||||
static_assert(quantity<meter, int>(km).count() == km.count());
|
||||
static_assert(quantity<metre, int>(km).count() == km.count());
|
||||
|
||||
static_assert(quantity<meter, int>(1).count() == 1);
|
||||
static_assert(quantity<meter, int>(my_value(1)).count() == 1);
|
||||
static_assert(quantity<meter, my_value<int>>(1).count() == 1);
|
||||
// static_assert(quantity<meter, int>(1.0).count() == 1); // should not compile
|
||||
// static_assert(quantity<meter, int>(my_value(1.0)).count() == 1); // should not compile
|
||||
// static_assert(quantity<meter, my_value>(1.0).count() == 1); // should not compile
|
||||
static_assert(quantity<meter, double>(1.0).count() == 1.0);
|
||||
static_assert(quantity<meter, double>(my_value(1.0)).count() == 1.0);
|
||||
static_assert(quantity<meter, double>(1).count() == 1.0);
|
||||
static_assert(quantity<meter, double>(my_value(1)).count() == 1.0);
|
||||
static_assert(quantity<meter, double>(3.14).count() == 3.14);
|
||||
static_assert(quantity<meter, my_value<double>>(1.0).count() == 1.0);
|
||||
static_assert(quantity<meter, my_value<double>>(1).count() == 1.0);
|
||||
static_assert(quantity<meter, my_value<double>>(3.14).count() == 3.14);
|
||||
static_assert(quantity<metre, int>(1).count() == 1);
|
||||
static_assert(quantity<metre, int>(my_value(1)).count() == 1);
|
||||
static_assert(quantity<metre, my_value<int>>(1).count() == 1);
|
||||
// static_assert(quantity<metre, int>(1.0).count() == 1); // should not compile
|
||||
// static_assert(quantity<metre, int>(my_value(1.0)).count() == 1); // should not compile
|
||||
// static_assert(quantity<metre, my_value>(1.0).count() == 1); // should not compile
|
||||
static_assert(quantity<metre, double>(1.0).count() == 1.0);
|
||||
static_assert(quantity<metre, double>(my_value(1.0)).count() == 1.0);
|
||||
static_assert(quantity<metre, double>(1).count() == 1.0);
|
||||
static_assert(quantity<metre, double>(my_value(1)).count() == 1.0);
|
||||
static_assert(quantity<metre, double>(3.14).count() == 3.14);
|
||||
static_assert(quantity<metre, my_value<double>>(1.0).count() == 1.0);
|
||||
static_assert(quantity<metre, my_value<double>>(1).count() == 1.0);
|
||||
static_assert(quantity<metre, my_value<double>>(3.14).count() == 3.14);
|
||||
|
||||
static_assert(quantity<meter, int>(km).count() == 1000);
|
||||
// static_assert(quantity<meter, int>(quantity<meter, double>(3.14)).count() == 3); // should not compile
|
||||
static_assert(quantity<meter, int>(quantity_cast<quantity<meter, my_value<int>>>(3.14m)).count() == 3);
|
||||
// static_assert(quantity<meter, int>(quantity<meter, my_value<double>>(1000.0)).count() == 1000); // should not compile
|
||||
// static_assert(quantity<meter, my_value>(1000.0m).count() == 1000); // should not compile
|
||||
static_assert(quantity<meter, double>(1000.0m).count() == 1000.0);
|
||||
static_assert(quantity<meter, double>(quantity<meter, my_value<double>>(1000.0)).count() == 1000.0);
|
||||
static_assert(quantity<meter, my_value<double>>(1000.0m).count() == 1000.0);
|
||||
static_assert(quantity<meter, double>(km).count() == 1000.0);
|
||||
static_assert(quantity<meter, my_value<double>>(km).count() == 1000.0);
|
||||
static_assert(quantity<meter, int>(1km).count() == 1000);
|
||||
// static_assert(quantity<meter, int>(1_s).count() == 1); // should not compile
|
||||
// static_assert(quantity<kilometer, int>(1010m).count() == 1); // should not compile
|
||||
static_assert(quantity<kilometer, int>(quantity_cast<quantity<kilometer, my_value<int>>>(1010m)).count() == 1);
|
||||
static_assert(quantity<metre, int>(km).count() == 1000);
|
||||
// static_assert(quantity<metre, int>(quantity<metre, double>(3.14)).count() == 3); // should not compile
|
||||
static_assert(quantity<metre, int>(quantity_cast<quantity<metre, my_value<int>>>(3.14m)).count() == 3);
|
||||
// static_assert(quantity<metre, int>(quantity<metre, my_value<double>>(1000.0)).count() == 1000); // should not compile
|
||||
// static_assert(quantity<metre, my_value>(1000.0m).count() == 1000); // should not compile
|
||||
static_assert(quantity<metre, double>(1000.0m).count() == 1000.0);
|
||||
static_assert(quantity<metre, double>(quantity<metre, my_value<double>>(1000.0)).count() == 1000.0);
|
||||
static_assert(quantity<metre, my_value<double>>(1000.0m).count() == 1000.0);
|
||||
static_assert(quantity<metre, double>(km).count() == 1000.0);
|
||||
static_assert(quantity<metre, my_value<double>>(km).count() == 1000.0);
|
||||
static_assert(quantity<metre, int>(1km).count() == 1000);
|
||||
// static_assert(quantity<metre, int>(1_s).count() == 1); // should not compile
|
||||
// static_assert(quantity<kilometre, int>(1010m).count() == 1); // should not compile
|
||||
static_assert(quantity<kilometre, int>(quantity_cast<quantity<kilometre, my_value<int>>>(1010m)).count() == 1);
|
||||
|
||||
// assignment operator
|
||||
|
||||
static_assert([]() {
|
||||
quantity<meter, int> l1(1), l2(2);
|
||||
quantity<metre, int> l1(1), l2(2);
|
||||
return l2 = l1;
|
||||
}()
|
||||
.count() == 1);
|
||||
|
||||
// static member functions
|
||||
|
||||
static_assert(quantity<meter, int>::zero().count() == 0);
|
||||
static_assert(quantity<meter, int>::min().count() == std::numeric_limits<int>::lowest());
|
||||
static_assert(quantity<meter, int>::max().count() == std::numeric_limits<int>::max());
|
||||
static_assert(quantity<meter, double>::zero().count() == 0.0);
|
||||
static_assert(quantity<meter, double>::min().count() == std::numeric_limits<double>::lowest());
|
||||
static_assert(quantity<meter, double>::max().count() == std::numeric_limits<double>::max());
|
||||
static_assert(quantity<meter, my_value<int>>::zero().count() == 0);
|
||||
static_assert(quantity<meter, my_value<int>>::min().count() == std::numeric_limits<int>::lowest());
|
||||
static_assert(quantity<meter, my_value<int>>::max().count() == std::numeric_limits<int>::max());
|
||||
static_assert(quantity<meter, my_value<double>>::zero().count() == 0.0);
|
||||
static_assert(quantity<meter, my_value<double>>::min().count() == std::numeric_limits<double>::lowest());
|
||||
static_assert(quantity<meter, my_value<double>>::max().count() == std::numeric_limits<double>::max());
|
||||
static_assert(quantity<metre, int>::zero().count() == 0);
|
||||
static_assert(quantity<metre, int>::min().count() == std::numeric_limits<int>::lowest());
|
||||
static_assert(quantity<metre, int>::max().count() == std::numeric_limits<int>::max());
|
||||
static_assert(quantity<metre, double>::zero().count() == 0.0);
|
||||
static_assert(quantity<metre, double>::min().count() == std::numeric_limits<double>::lowest());
|
||||
static_assert(quantity<metre, double>::max().count() == std::numeric_limits<double>::max());
|
||||
static_assert(quantity<metre, my_value<int>>::zero().count() == 0);
|
||||
static_assert(quantity<metre, my_value<int>>::min().count() == std::numeric_limits<int>::lowest());
|
||||
static_assert(quantity<metre, my_value<int>>::max().count() == std::numeric_limits<int>::max());
|
||||
static_assert(quantity<metre, my_value<double>>::zero().count() == 0.0);
|
||||
static_assert(quantity<metre, my_value<double>>::min().count() == std::numeric_limits<double>::lowest());
|
||||
static_assert(quantity<metre, my_value<double>>::max().count() == std::numeric_limits<double>::max());
|
||||
|
||||
// unary member operators
|
||||
|
||||
@@ -160,19 +160,19 @@ namespace {
|
||||
static_assert([](auto v) {
|
||||
auto vv = v++;
|
||||
return std::make_pair(v, vv);
|
||||
}(km) == std::make_pair(quantity<meter, int>(1001), quantity<meter, int>(1000)));
|
||||
}(km) == std::make_pair(quantity<metre, int>(1001), quantity<metre, int>(1000)));
|
||||
static_assert([](auto v) {
|
||||
auto vv = ++v;
|
||||
return std::make_pair(v, vv);
|
||||
}(km) == std::make_pair(quantity<meter, int>(1001), quantity<meter, int>(1001)));
|
||||
}(km) == std::make_pair(quantity<metre, int>(1001), quantity<metre, int>(1001)));
|
||||
static_assert([](auto v) {
|
||||
auto vv = v--;
|
||||
return std::make_pair(v, vv);
|
||||
}(km) == std::make_pair(quantity<meter, int>(999), quantity<meter, int>(1000)));
|
||||
}(km) == std::make_pair(quantity<metre, int>(999), quantity<metre, int>(1000)));
|
||||
static_assert([](auto v) {
|
||||
auto vv = --v;
|
||||
return std::make_pair(v, vv);
|
||||
}(km) == std::make_pair(quantity<meter, int>(999), quantity<meter, int>(999)));
|
||||
}(km) == std::make_pair(quantity<metre, int>(999), quantity<metre, int>(999)));
|
||||
|
||||
// compound assignment
|
||||
|
||||
@@ -185,21 +185,21 @@ namespace {
|
||||
|
||||
// non-member arithmetic operators
|
||||
|
||||
static_assert(std::is_same_v<decltype(quantity<meter, int>() + quantity<meter, double>()), quantity<meter, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<meter, int>() + quantity<meter, double>()), quantity<meter, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<kilometer, int>() + quantity<meter, double>()), quantity<meter, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<meter, double>() - quantity<meter, int>()), quantity<meter, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<kilometer, double>() - quantity<meter, int>()), quantity<meter, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<meter, int>() * 1.0), quantity<meter, double>>);
|
||||
static_assert(std::is_same_v<decltype(1.0 * quantity<meter, int>()), quantity<meter, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<meter_per_second, int>() * quantity<second, int>()), quantity<meter, int>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<metre, int>() + quantity<metre, double>()), quantity<metre, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<metre, int>() + quantity<metre, double>()), quantity<metre, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<kilometre, int>() + quantity<metre, double>()), quantity<metre, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<metre, double>() - quantity<metre, int>()), quantity<metre, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<kilometre, double>() - quantity<metre, int>()), quantity<metre, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<metre, int>() * 1.0), quantity<metre, double>>);
|
||||
static_assert(std::is_same_v<decltype(1.0 * quantity<metre, int>()), quantity<metre, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<metre_per_second, int>() * quantity<second, int>()), quantity<metre, int>>);
|
||||
static_assert(std::is_same_v<decltype(1 / quantity<second, int>()), quantity<hertz, int>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<meter, int>() / 1.0), quantity<meter, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<meter, int>() / quantity<meter, double>()), double>);
|
||||
static_assert(std::is_same_v<decltype(quantity<kilometer, int>() / quantity<meter, double>()), double>);
|
||||
static_assert(std::is_same_v<decltype(quantity<meter, int>() / quantity<second, int>()), quantity<meter_per_second, int>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<meter, int>() % short(1)), quantity<meter, int>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<meter, int>() % quantity<meter, short>(1)), quantity<meter, int>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<metre, int>() / 1.0), quantity<metre, double>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<metre, int>() / quantity<metre, double>()), double>);
|
||||
static_assert(std::is_same_v<decltype(quantity<kilometre, int>() / quantity<metre, double>()), double>);
|
||||
static_assert(std::is_same_v<decltype(quantity<metre, int>() / quantity<second, int>()), quantity<metre_per_second, int>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<metre, int>() % short(1)), quantity<metre, int>>);
|
||||
static_assert(std::is_same_v<decltype(quantity<metre, int>() % quantity<metre, short>(1)), quantity<metre, int>>);
|
||||
|
||||
static_assert((1m + km).count() == 1001);
|
||||
static_assert((1m + 1km).count() == 1001);
|
||||
@@ -247,19 +247,19 @@ namespace {
|
||||
|
||||
// is_quantity
|
||||
|
||||
static_assert(Quantity<quantity<millimeter, int>>);
|
||||
static_assert(Quantity<quantity<millimetre, int>>);
|
||||
|
||||
// common_quantity
|
||||
|
||||
static_assert(std::is_same_v<common_quantity_t<quantity<meter, int>, quantity<kilometer, int>>, quantity<meter, int>>);
|
||||
static_assert(std::is_same_v<common_quantity_t<quantity<kilometer, long long>, quantity<meter, int>>, quantity<meter, long long>>);
|
||||
static_assert(std::is_same_v<common_quantity_t<quantity<kilometer, long long>, quantity<millimeter, double>>, quantity<millimeter, double>>);
|
||||
static_assert(std::is_same_v<common_quantity_t<quantity<metre, int>, quantity<kilometre, int>>, quantity<metre, int>>);
|
||||
static_assert(std::is_same_v<common_quantity_t<quantity<kilometre, long long>, quantity<metre, int>>, quantity<metre, long long>>);
|
||||
static_assert(std::is_same_v<common_quantity_t<quantity<kilometre, long long>, quantity<millimetre, double>>, quantity<millimetre, double>>);
|
||||
|
||||
// quantity_cast
|
||||
|
||||
// static_assert(quantity_cast<int>(2km).count() == 2000); // should not compile
|
||||
static_assert(quantity_cast<quantity<meter, int>>(2km).count() == 2000);
|
||||
static_assert(quantity_cast<quantity<kilometer, int>>(2000m).count() == 2);
|
||||
static_assert(quantity_cast<quantity<metre, int>>(2km).count() == 2000);
|
||||
static_assert(quantity_cast<quantity<kilometre, int>>(2000m).count() == 2);
|
||||
|
||||
// time
|
||||
|
||||
|
@@ -135,7 +135,7 @@ namespace {
|
||||
|
||||
static_assert(2km / 2kmph == 1h);
|
||||
// static_assert(2000m / 2kmph == 1h); // should not compile
|
||||
static_assert(quantity_cast<quantity<kilometer, int>>(2000m) / 2kmph == 1h);
|
||||
static_assert(quantity_cast<quantity<kilometre, int>>(2000m) / 2kmph == 1h);
|
||||
|
||||
// acceleration
|
||||
|
||||
|
Reference in New Issue
Block a user