mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 19:04:27 +02:00
Leading underscore prefix removed from UDLs
This commit is contained in:
@@ -10,20 +10,20 @@ Here is a small example of possible operations:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// simple numeric operations
|
// simple numeric operations
|
||||||
static_assert(10_km / 2 == 5_km);
|
static_assert(10km / 2 == 5km);
|
||||||
|
|
||||||
// unit conversions
|
// unit conversions
|
||||||
static_assert(1_h == 3600_s);
|
static_assert(1h == 3600s);
|
||||||
static_assert(1_km + 1_m == 1001_m);
|
static_assert(1km + 1m == 1001m);
|
||||||
|
|
||||||
// dimension conversions
|
// dimension conversions
|
||||||
static_assert(1_km / 1_s == 1000_mps);
|
static_assert(1km / 1s == 1000mps);
|
||||||
static_assert(2_kmph * 2_h == 4_km);
|
static_assert(2kmph * 2h == 4km);
|
||||||
static_assert(2_km / 2_kmph == 1_h);
|
static_assert(2km / 2kmph == 1h);
|
||||||
|
|
||||||
static_assert(1000 / 1_s == 1_kHz);
|
static_assert(1000 / 1s == 1kHz);
|
||||||
|
|
||||||
static_assert(10_km / 5_km == 2);
|
static_assert(10km / 5km == 2);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ Quantity is a concrete amount of a unit for a specified dimension with a specifi
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
units::quantity<units::kilometer, double> d1(123);
|
units::quantity<units::kilometer, double> d1(123);
|
||||||
auto d2 = 123_km; // stde::units::quantity<units::kilometer, std::int64_t>
|
auto d2 = 123km; // stde::units::quantity<units::kilometer, std::int64_t>
|
||||||
```
|
```
|
||||||
|
|
||||||
There are C++ concepts provided for each such quantity type:
|
There are C++ concepts provided for each such quantity type:
|
||||||
@@ -136,8 +136,8 @@ those base dimensions that are used to form that derived dimension.
|
|||||||
However, such an approach have some challenges:
|
However, such an approach have some challenges:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
constexpr Velocity auto v1 = 1_m / 1_s;
|
constexpr Velocity auto v1 = 1_m / 1s;
|
||||||
constexpr Velocity auto v2 = 2 / 2_s * 1_m;
|
constexpr Velocity auto v2 = 2 / 2s * 1m;
|
||||||
|
|
||||||
static_assert(std::Same<decltype(v1), decltype(v2)>);
|
static_assert(std::Same<decltype(v1), decltype(v2)>);
|
||||||
static_assert(v1 == v2);
|
static_assert(v1 == v2);
|
||||||
@@ -306,14 +306,14 @@ the best user experience as possible.
|
|||||||
For example with template aliases usage the following code:
|
For example with template aliases usage the following code:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
const Velocity auto t = 20_s;
|
const Velocity auto t = 20s;
|
||||||
```
|
```
|
||||||
|
|
||||||
could generate a following compile time error:
|
could generate a following compile time error:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
<path>\example\example.cpp:39:22: error: deduced initializer does not satisfy placeholder constraints
|
<path>\example\example.cpp:39:22: error: deduced initializer does not satisfy placeholder constraints
|
||||||
const Velocity auto t = 20_s;
|
const Velocity auto t = 20s;
|
||||||
^~~~
|
^~~~
|
||||||
In file included from <path>\example\example.cpp:23:
|
In file included from <path>\example\example.cpp:23:
|
||||||
<path>/src/include/units/si/velocity.h:41:16: note: within 'template<class T> concept const bool stde::units::Velocity<T> [with T = stde::units::quantity<units::unit<units::dimension<units::exp<units::base_dim_time, 1> >, std::ratio<1> >, long long int>]'
|
<path>/src/include/units/si/velocity.h:41:16: note: within 'template<class T> concept const bool stde::units::Velocity<T> [with T = stde::units::quantity<units::unit<units::dimension<units::exp<units::base_dim_time, 1> >, std::ratio<1> >, long long int>]'
|
||||||
@@ -350,7 +350,7 @@ same code will result with such an error:
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
<path>\example\example.cpp:40:22: error: deduced initializer does not satisfy placeholder constraints
|
<path>\example\example.cpp:40:22: error: deduced initializer does not satisfy placeholder constraints
|
||||||
const Velocity t = 20_s;
|
const Velocity t = 20s;
|
||||||
^~~~
|
^~~~
|
||||||
In file included from <path>\example\example.cpp:23:
|
In file included from <path>\example\example.cpp:23:
|
||||||
<path>/src/include/units/si/velocity.h:48:16: note: within 'template<class T> concept const bool stde::units::Velocity<T> [with T = stde::units::quantity<units::second, long long int>]'
|
<path>/src/include/units/si/velocity.h:48:16: note: within 'template<class T> concept const bool stde::units::Velocity<T> [with T = stde::units::quantity<units::second, long long int>]'
|
||||||
@@ -528,7 +528,7 @@ Additionally, it should make the error logs even shorter thus easier to understa
|
|||||||
|
|
||||||
7. Should we provide cmath-like functions for quantities?
|
7. Should we provide cmath-like functions for quantities?
|
||||||
|
|
||||||
8. What should be the resulting type of `auto d = 1_km + 1_ft;`?
|
8. What should be the resulting type of `auto d = 1km + 1ft;`?
|
||||||
|
|
||||||
9. Should we require explicit casts (i.e. quantity_cast) between different systems of
|
9. Should we require explicit casts (i.e. quantity_cast) between different systems of
|
||||||
measurement?
|
measurement?
|
||||||
@@ -546,3 +546,6 @@ Additionally, it should make the error logs even shorter thus easier to understa
|
|||||||
13. Should we standardize accompany tools (`downcasting_traits`, `type_list` operations, `common_ratio`, etc)?
|
13. Should we standardize accompany tools (`downcasting_traits`, `type_list` operations, `common_ratio`, etc)?
|
||||||
|
|
||||||
14. Do we need to support fractional exponents (i.e. `dimension<exp<"length", 2, 3>>` as 2/3)?
|
14. Do we need to support fractional exponents (i.e. `dimension<exp<"length", 2, 3>>` as 2/3)?
|
||||||
|
|
||||||
|
15. `k` and `K` UDLs conflict with gcc GNU extensions (https://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Fixed_002dPoint.html)
|
||||||
|
for floating point types.
|
||||||
|
@@ -56,7 +56,7 @@ void example_2(double distance_v, double duration_v)
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
example_1(60_kmph, 10.0_min);
|
example_1(60kmph, 10.0min);
|
||||||
example_2(220, 2);
|
example_2(220, 2);
|
||||||
}
|
}
|
||||||
catch (const std::exception& ex) {
|
catch (const std::exception& ex) {
|
||||||
|
@@ -65,6 +65,10 @@ target_include_directories(units
|
|||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
||||||
$<INSTALL_INTERFACE:include>
|
$<INSTALL_INTERFACE:include>
|
||||||
)
|
)
|
||||||
|
target_compile_options(units
|
||||||
|
INTERFACE
|
||||||
|
-Wno-literal-suffix
|
||||||
|
)
|
||||||
add_library(mp::units ALIAS units)
|
add_library(mp::units ALIAS units)
|
||||||
|
|
||||||
# installation info
|
# installation info
|
||||||
|
@@ -50,20 +50,20 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// sq_mm
|
// sq_mm
|
||||||
constexpr auto operator""_sq_mm(unsigned long long l) { return quantity<square_millimeter, std::int64_t>(l); }
|
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(long double l) { return quantity<square_millimeter, long double>(l); }
|
||||||
|
|
||||||
// sq_cm
|
// sq_cm
|
||||||
constexpr auto operator""_sq_cm(unsigned long long l) { return quantity<square_centimeter, std::int64_t>(l); }
|
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(long double l) { return quantity<square_centimeter, long double>(l); }
|
||||||
|
|
||||||
// sq_m
|
// sq_m
|
||||||
constexpr auto operator""_sq_m(unsigned long long l) { return quantity<square_meter, std::int64_t>(l); }
|
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(long double l) { return quantity<square_meter, long double>(l); }
|
||||||
|
|
||||||
// sq_km
|
// sq_km
|
||||||
constexpr auto operator""_sq_km(unsigned long long l) { return quantity<square_kilometer, std::int64_t>(l); }
|
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(long double l) { return quantity<square_kilometer, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
|
@@ -39,8 +39,8 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// A
|
// A
|
||||||
constexpr auto operator""_A(unsigned long long l) { return quantity<ampere, std::int64_t>(l); }
|
constexpr auto operator""A(unsigned long long l) { return quantity<ampere, std::int64_t>(l); }
|
||||||
constexpr auto operator""_A(long double l) { return quantity<ampere, long double>(l); }
|
constexpr auto operator""A(long double l) { return quantity<ampere, long double>(l); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,28 +54,28 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// mHz
|
// mHz
|
||||||
constexpr auto operator""_mHz(unsigned long long l) { return quantity<millihertz, std::int64_t>(l); }
|
constexpr auto operator""mHz(unsigned long long l) { return quantity<millihertz, std::int64_t>(l); }
|
||||||
constexpr auto operator""_mHz(long double l) { return quantity<millihertz, long double>(l); }
|
constexpr auto operator""mHz(long double l) { return quantity<millihertz, long double>(l); }
|
||||||
|
|
||||||
// Hz
|
// Hz
|
||||||
constexpr auto operator""_Hz(unsigned long long l) { return quantity<hertz, std::int64_t>(l); }
|
constexpr auto operator""Hz(unsigned long long l) { return quantity<hertz, std::int64_t>(l); }
|
||||||
constexpr auto operator""_Hz(long double l) { return quantity<hertz, long double>(l); }
|
constexpr auto operator""Hz(long double l) { return quantity<hertz, long double>(l); }
|
||||||
|
|
||||||
// kHz
|
// kHz
|
||||||
constexpr auto operator""_kHz(unsigned long long l) { return quantity<kilohertz, std::int64_t>(l); }
|
constexpr auto operator""kHz(unsigned long long l) { return quantity<kilohertz, std::int64_t>(l); }
|
||||||
constexpr auto operator""_kHz(long double l) { return quantity<kilohertz, long double>(l); }
|
constexpr auto operator""kHz(long double l) { return quantity<kilohertz, long double>(l); }
|
||||||
|
|
||||||
// MHz
|
// MHz
|
||||||
constexpr auto operator""_MHz(unsigned long long l) { return quantity<megahertz, std::int64_t>(l); }
|
constexpr auto operator""MHz(unsigned long long l) { return quantity<megahertz, std::int64_t>(l); }
|
||||||
constexpr auto operator""_MHz(long double l) { return quantity<megahertz, long double>(l); }
|
constexpr auto operator""MHz(long double l) { return quantity<megahertz, long double>(l); }
|
||||||
|
|
||||||
// GHz
|
// GHz
|
||||||
constexpr auto operator""_GHz(unsigned long long l) { return quantity<gigahertz, std::int64_t>(l); }
|
constexpr auto operator""GHz(unsigned long long l) { return quantity<gigahertz, std::int64_t>(l); }
|
||||||
constexpr auto operator""_GHz(long double l) { return quantity<gigahertz, long double>(l); }
|
constexpr auto operator""GHz(long double l) { return quantity<gigahertz, long double>(l); }
|
||||||
|
|
||||||
// THz
|
// THz
|
||||||
constexpr auto operator""_THz(unsigned long long l) { return quantity<terahertz, std::int64_t>(l); }
|
constexpr auto operator""THz(unsigned long long l) { return quantity<terahertz, std::int64_t>(l); }
|
||||||
constexpr auto operator""_THz(long double l) { return quantity<terahertz, long double>(l); }
|
constexpr auto operator""THz(long double l) { return quantity<terahertz, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
|
@@ -49,20 +49,20 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// mm
|
// mm
|
||||||
constexpr auto operator""_mm(unsigned long long l) { return quantity<millimeter, std::int64_t>(l); }
|
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(long double l) { return quantity<millimeter, long double>(l); }
|
||||||
|
|
||||||
// cm
|
// cm
|
||||||
constexpr auto operator""_cm(unsigned long long l) { return quantity<centimeter, std::int64_t>(l); }
|
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(long double l) { return quantity<centimeter, long double>(l); }
|
||||||
|
|
||||||
// m
|
// m
|
||||||
constexpr auto operator""_m(unsigned long long l) { return quantity<meter, std::int64_t>(l); }
|
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(long double l) { return quantity<meter, long double>(l); }
|
||||||
|
|
||||||
// km
|
// km
|
||||||
constexpr auto operator""_km(unsigned long long l) { return quantity<kilometer, std::int64_t>(l); }
|
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(long double l) { return quantity<kilometer, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
@@ -82,20 +82,20 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// yd
|
// yd
|
||||||
constexpr auto operator""_yd(unsigned long long l) { return quantity<yard, std::int64_t>(l); }
|
constexpr auto operator""yd(unsigned long long l) { return quantity<yard, std::int64_t>(l); }
|
||||||
constexpr auto operator""_yd(long double l) { return quantity<yard, long double>(l); }
|
constexpr auto operator""yd(long double l) { return quantity<yard, long double>(l); }
|
||||||
|
|
||||||
// ft
|
// ft
|
||||||
constexpr auto operator""_ft(unsigned long long l) { return quantity<foot, std::int64_t>(l); }
|
constexpr auto operator""ft(unsigned long long l) { return quantity<foot, std::int64_t>(l); }
|
||||||
constexpr auto operator""_ft(long double l) { return quantity<foot, long double>(l); }
|
constexpr auto operator""ft(long double l) { return quantity<foot, long double>(l); }
|
||||||
|
|
||||||
// in
|
// in
|
||||||
constexpr auto operator""_in(unsigned long long l) { return quantity<inch, std::int64_t>(l); }
|
constexpr auto operator""in(unsigned long long l) { return quantity<inch, std::int64_t>(l); }
|
||||||
constexpr auto operator""_in(long double l) { return quantity<inch, long double>(l); }
|
constexpr auto operator""in(long double l) { return quantity<inch, long double>(l); }
|
||||||
|
|
||||||
// mi
|
// mi
|
||||||
constexpr auto operator""_mi(unsigned long long l) { return quantity<mile, std::int64_t>(l); }
|
constexpr auto operator""mi(unsigned long long l) { return quantity<mile, std::int64_t>(l); }
|
||||||
constexpr auto operator""_mi(long double l) { return quantity<mile, long double>(l); }
|
constexpr auto operator""mi(long double l) { return quantity<mile, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
|
@@ -39,8 +39,8 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// cd
|
// cd
|
||||||
constexpr auto operator""_cd(unsigned long long l) { return quantity<candela, std::int64_t>(l); }
|
constexpr auto operator""cd(unsigned long long l) { return quantity<candela, std::int64_t>(l); }
|
||||||
constexpr auto operator""_cd(long double l) { return quantity<candela, long double>(l); }
|
constexpr auto operator""cd(long double l) { return quantity<candela, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
|
@@ -42,12 +42,12 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// g
|
// g
|
||||||
constexpr auto operator""_g(unsigned long long l) { return quantity<gram, std::int64_t>(l); }
|
constexpr auto operator""g(unsigned long long l) { return quantity<gram, std::int64_t>(l); }
|
||||||
constexpr auto operator""_g(long double l) { return quantity<gram, long double>(l); }
|
constexpr auto operator""g(long double l) { return quantity<gram, long double>(l); }
|
||||||
|
|
||||||
// kg
|
// kg
|
||||||
constexpr auto operator""_kg(unsigned long long l) { return quantity<kilogram, std::int64_t>(l); }
|
constexpr auto operator""kg(unsigned long long l) { return quantity<kilogram, std::int64_t>(l); }
|
||||||
constexpr auto operator""_kg(long double l) { return quantity<kilogram, long double>(l); }
|
constexpr auto operator""kg(long double l) { return quantity<kilogram, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
|
@@ -39,8 +39,8 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// mol
|
// mol
|
||||||
constexpr auto operator""_mol(unsigned long long l) { return quantity<mole, std::int64_t>(l); }
|
constexpr auto operator""mol(unsigned long long l) { return quantity<mole, std::int64_t>(l); }
|
||||||
constexpr auto operator""_mol(long double l) { return quantity<mole, long double>(l); }
|
constexpr auto operator""mol(long double l) { return quantity<mole, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
|
@@ -39,8 +39,8 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// K
|
// K
|
||||||
constexpr auto operator""_K(unsigned long long l) { return quantity<kelvin, std::int64_t>(l); }
|
constexpr auto operator""K(unsigned long long l) { return quantity<kelvin, std::int64_t>(l); }
|
||||||
constexpr auto operator""_K(long double l) { return quantity<kelvin, long double>(l); }
|
constexpr auto operator""_K(long double l) { return quantity<kelvin, long double>(l); } // todo: conflicts with gcc GNU extension
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
|
@@ -54,28 +54,28 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// ns
|
// ns
|
||||||
constexpr auto operator""_ns(unsigned long long l) { return quantity<nanosecond, std::int64_t>(l); }
|
constexpr auto operator""ns(unsigned long long l) { return quantity<nanosecond, std::int64_t>(l); }
|
||||||
constexpr auto operator""_ns(long double l) { return quantity<nanosecond, long double>(l); }
|
constexpr auto operator""ns(long double l) { return quantity<nanosecond, long double>(l); }
|
||||||
|
|
||||||
// us
|
// us
|
||||||
constexpr auto operator""_us(unsigned long long l) { return quantity<microsecond, std::int64_t>(l); }
|
constexpr auto operator""us(unsigned long long l) { return quantity<microsecond, std::int64_t>(l); }
|
||||||
constexpr auto operator""_us(long double l) { return quantity<microsecond, long double>(l); }
|
constexpr auto operator""us(long double l) { return quantity<microsecond, long double>(l); }
|
||||||
|
|
||||||
// ms
|
// ms
|
||||||
constexpr auto operator""_ms(unsigned long long l) { return quantity<millisecond, std::int64_t>(l); }
|
constexpr auto operator""ms(unsigned long long l) { return quantity<millisecond, std::int64_t>(l); }
|
||||||
constexpr auto operator""_ms(long double l) { return quantity<millisecond, long double>(l); }
|
constexpr auto operator""ms(long double l) { return quantity<millisecond, long double>(l); }
|
||||||
|
|
||||||
// s
|
// s
|
||||||
constexpr auto operator""_s(unsigned long long l) { return quantity<second, std::int64_t>(l); }
|
constexpr auto operator""s(unsigned long long l) { return quantity<second, std::int64_t>(l); }
|
||||||
constexpr auto operator""_s(long double l) { return quantity<second, long double>(l); }
|
constexpr auto operator""s(long double l) { return quantity<second, long double>(l); }
|
||||||
|
|
||||||
// min
|
// min
|
||||||
constexpr auto operator""_min(unsigned long long l) { return quantity<minute, std::int64_t>(l); }
|
constexpr auto operator""min(unsigned long long l) { return quantity<minute, std::int64_t>(l); }
|
||||||
constexpr auto operator""_min(long double l) { return quantity<minute, long double>(l); }
|
constexpr auto operator""min(long double l) { return quantity<minute, long double>(l); }
|
||||||
|
|
||||||
// h
|
// h
|
||||||
constexpr auto operator""_h(unsigned long long l) { return quantity<hour, std::int64_t>(l); }
|
constexpr auto operator""h(unsigned long long l) { return quantity<hour, std::int64_t>(l); }
|
||||||
constexpr auto operator""_h(long double l) { return quantity<hour, long double>(l); }
|
constexpr auto operator""h(long double l) { return quantity<hour, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
|
@@ -45,16 +45,16 @@ namespace std::experimental::units {
|
|||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
|
|
||||||
// mps
|
// mps
|
||||||
constexpr auto operator""_mps(unsigned long long l) { return quantity<meter_per_second, std::int64_t>(l); }
|
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(long double l) { return quantity<meter_per_second, long double>(l); }
|
||||||
|
|
||||||
// kmph
|
// kmph
|
||||||
constexpr auto operator""_kmph(unsigned long long l) { return quantity<kilometer_per_hour, std::int64_t>(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(long double l) { return quantity<kilometer_per_hour, long double>(l); }
|
||||||
|
|
||||||
// mph
|
// mph
|
||||||
constexpr auto operator""_mph(unsigned long long l) { return quantity<mile_per_hour, std::int64_t>(l); }
|
constexpr auto operator""mph(unsigned long long l) { return quantity<mile_per_hour, std::int64_t>(l); }
|
||||||
constexpr auto operator""_mph(long double l) { return quantity<mile_per_hour, long double>(l); }
|
constexpr auto operator""mph(long double l) { return quantity<mile_per_hour, long double>(l); }
|
||||||
|
|
||||||
} // namespace literals
|
} // namespace literals
|
||||||
|
|
||||||
|
@@ -77,7 +77,7 @@ namespace {
|
|||||||
// class invariants
|
// class invariants
|
||||||
|
|
||||||
// constexpr quantity<dimension_length, second, int> q; // should a static_assert
|
// constexpr quantity<dimension_length, second, int> q; // should a static_assert
|
||||||
// constexpr quantity<dimension_length, meter, quantity<meter, int>> error(0_m); // should trigger a static_assert
|
// constexpr quantity<dimension_length, meter, quantity<meter, int>> error(0m); // should trigger a static_assert
|
||||||
// constexpr quantity<int, int, double> error(0); // 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
|
// constexpr quantity<dimension_length, unit<dimension_length, std::ratio<-1, 1>>, int> error(0); // should trigger a static_assert
|
||||||
|
|
||||||
@@ -112,18 +112,18 @@ namespace {
|
|||||||
|
|
||||||
static_assert(quantity<meter, int>(km).count() == 1000);
|
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<meter, double>(3.14)).count() == 3); // should not compile
|
||||||
static_assert(quantity<meter, int>(quantity_cast<quantity<meter, my_value<int>>>(3.14_m)).count() == 3);
|
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, int>(quantity<meter, my_value<double>>(1000.0)).count() == 1000); // should not compile
|
||||||
// static_assert(quantity<meter, my_value>(1000.0_m).count() == 1000); // should not compile
|
// static_assert(quantity<meter, my_value>(1000.0m).count() == 1000); // should not compile
|
||||||
static_assert(quantity<meter, double>(1000.0_m).count() == 1000.0);
|
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, double>(quantity<meter, my_value<double>>(1000.0)).count() == 1000.0);
|
||||||
static_assert(quantity<meter, my_value<double>>(1000.0_m).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, double>(km).count() == 1000.0);
|
||||||
static_assert(quantity<meter, my_value<double>>(km).count() == 1000.0);
|
static_assert(quantity<meter, my_value<double>>(km).count() == 1000.0);
|
||||||
static_assert(quantity<meter, int>(1_km).count() == 1000);
|
static_assert(quantity<meter, int>(1km).count() == 1000);
|
||||||
// static_assert(quantity<meter, int>(1_s).count() == 1); // should not compile
|
// static_assert(quantity<meter, int>(1_s).count() == 1); // should not compile
|
||||||
// static_assert(quantity<kilometer, int>(1010_m).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>>>(1010_m)).count() == 1);
|
static_assert(quantity<kilometer, int>(quantity_cast<quantity<kilometer, my_value<int>>>(1010m)).count() == 1);
|
||||||
|
|
||||||
// assignment operator
|
// assignment operator
|
||||||
|
|
||||||
@@ -176,12 +176,12 @@ namespace {
|
|||||||
|
|
||||||
// compound assignment
|
// compound assignment
|
||||||
|
|
||||||
static_assert((1_m += 1_m).count() == 2);
|
static_assert((1m += 1m).count() == 2);
|
||||||
static_assert((2_m -= 1_m).count() == 1);
|
static_assert((2m -= 1m).count() == 1);
|
||||||
static_assert((1_m *= 2).count() == 2);
|
static_assert((1m *= 2).count() == 2);
|
||||||
static_assert((2_m /= 2).count() == 1);
|
static_assert((2m /= 2).count() == 1);
|
||||||
static_assert((7_m %= 2).count() == 1);
|
static_assert((7m %= 2).count() == 1);
|
||||||
static_assert((7_m %= 2_m).count() == 1);
|
static_assert((7m %= 2m).count() == 1);
|
||||||
|
|
||||||
// non-member arithmetic operators
|
// non-member arithmetic operators
|
||||||
|
|
||||||
@@ -201,49 +201,49 @@ namespace {
|
|||||||
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>() % 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<meter, int>() % quantity<meter, short>(1)), quantity<meter, int>>);
|
||||||
|
|
||||||
static_assert((1_m + km).count() == 1001);
|
static_assert((1m + km).count() == 1001);
|
||||||
static_assert((1_m + 1_km).count() == 1001);
|
static_assert((1m + 1km).count() == 1001);
|
||||||
static_assert((km - 1_m).count() == 999);
|
static_assert((km - 1m).count() == 999);
|
||||||
static_assert((1_km - 1_m).count() == 999);
|
static_assert((1km - 1m).count() == 999);
|
||||||
static_assert((2_m * 2).count() == 4);
|
static_assert((2m * 2).count() == 4);
|
||||||
static_assert((3 * 3_m).count() == 9);
|
static_assert((3 * 3m).count() == 9);
|
||||||
static_assert((4_m / 2).count() == 2);
|
static_assert((4m / 2).count() == 2);
|
||||||
static_assert(4_m / 2_m == 2);
|
static_assert(4m / 2m == 2);
|
||||||
static_assert(4_km / 2000_m == 2);
|
static_assert(4km / 2000m == 2);
|
||||||
static_assert((7_m % 2).count() == 1);
|
static_assert((7m % 2).count() == 1);
|
||||||
static_assert((7_m % 2_m).count() == 1);
|
static_assert((7m % 2m).count() == 1);
|
||||||
static_assert((7_km % 2000_m).count() == 1000);
|
static_assert((7km % 2000m).count() == 1000);
|
||||||
|
|
||||||
// comparators
|
// comparators
|
||||||
|
|
||||||
static_assert(2_m + 1_m == 3_m);
|
static_assert(2m + 1m == 3m);
|
||||||
static_assert(!(2_m + 2_m == 3_m));
|
static_assert(!(2m + 2m == 3m));
|
||||||
static_assert(2_m + 2_m != 3_m);
|
static_assert(2m + 2m != 3m);
|
||||||
static_assert(!(2_m + 2_m != 4_m));
|
static_assert(!(2m + 2m != 4m));
|
||||||
static_assert(2_m > 1_m);
|
static_assert(2m > 1m);
|
||||||
static_assert(!(1_m > 1_m));
|
static_assert(!(1m > 1m));
|
||||||
static_assert(1_m < 2_m);
|
static_assert(1m < 2m);
|
||||||
static_assert(!(2_m < 2_m));
|
static_assert(!(2m < 2m));
|
||||||
static_assert(2_m >= 1_m);
|
static_assert(2m >= 1m);
|
||||||
static_assert(2_m >= 2_m);
|
static_assert(2m >= 2m);
|
||||||
static_assert(!(2_m >= 3_m));
|
static_assert(!(2m >= 3m));
|
||||||
static_assert(1_m <= 2_m);
|
static_assert(1m <= 2m);
|
||||||
static_assert(2_m <= 2_m);
|
static_assert(2m <= 2m);
|
||||||
static_assert(!(3_m <= 2_m));
|
static_assert(!(3m <= 2m));
|
||||||
|
|
||||||
static_assert(3_m == 3.0_m);
|
static_assert(3m == 3.0m);
|
||||||
static_assert(3_m != 3.14_m);
|
static_assert(3m != 3.14m);
|
||||||
static_assert(2_m > 1.0_m);
|
static_assert(2m > 1.0m);
|
||||||
static_assert(1.0_m < 2_m);
|
static_assert(1.0m < 2m);
|
||||||
static_assert(2.0_m >= 1_m);
|
static_assert(2.0m >= 1m);
|
||||||
static_assert(1_m <= 2.0_m);
|
static_assert(1m <= 2.0m);
|
||||||
|
|
||||||
static_assert(1000_m == 1_km);
|
static_assert(1000m == 1km);
|
||||||
static_assert(1001_m != 1_km);
|
static_assert(1001m != 1km);
|
||||||
static_assert(1001_m > 1_km);
|
static_assert(1001m > 1km);
|
||||||
static_assert(999_m < 1_km);
|
static_assert(999m < 1km);
|
||||||
static_assert(1000_m >= 1_km);
|
static_assert(1000m >= 1km);
|
||||||
static_assert(1000_m <= 1_km);
|
static_assert(1000m <= 1km);
|
||||||
|
|
||||||
// is_quantity
|
// is_quantity
|
||||||
|
|
||||||
@@ -257,28 +257,28 @@ namespace {
|
|||||||
|
|
||||||
// quantity_cast
|
// quantity_cast
|
||||||
|
|
||||||
// static_assert(quantity_cast<int>(2_km).count() == 2000); // should not compile
|
// static_assert(quantity_cast<int>(2km).count() == 2000); // should not compile
|
||||||
static_assert(quantity_cast<quantity<meter, int>>(2_km).count() == 2000);
|
static_assert(quantity_cast<quantity<meter, int>>(2km).count() == 2000);
|
||||||
static_assert(quantity_cast<quantity<kilometer, int>>(2000_m).count() == 2);
|
static_assert(quantity_cast<quantity<kilometer, int>>(2000m).count() == 2);
|
||||||
|
|
||||||
// time
|
// time
|
||||||
|
|
||||||
// static_assert(1_s == 1_m); // should not compile
|
// static_assert(1s == 1m); // should not compile
|
||||||
static_assert(1_h == 3600_s);
|
static_assert(1h == 3600s);
|
||||||
|
|
||||||
// length
|
// length
|
||||||
|
|
||||||
static_assert(1_km == 1000_m);
|
static_assert(1km == 1000m);
|
||||||
static_assert(1_km + 1_m == 1001_m);
|
static_assert(1km + 1m == 1001m);
|
||||||
static_assert(10_km / 5_km == 2);
|
static_assert(10km / 5km == 2);
|
||||||
static_assert(10_km / 2 == 5_km);
|
static_assert(10km / 2 == 5km);
|
||||||
|
|
||||||
// velocity
|
// velocity
|
||||||
|
|
||||||
static_assert(10_m / 5_s == 2_mps);
|
static_assert(10m / 5s == 2mps);
|
||||||
static_assert(10 / 5_s * 1_m == 2_mps);
|
static_assert(10 / 5s * 1m == 2mps);
|
||||||
static_assert(1_km / 1_s == 1000_mps);
|
static_assert(1km / 1s == 1000mps);
|
||||||
static_assert(2_kmph * 2_h == 4_km);
|
static_assert(2kmph * 2h == 4km);
|
||||||
static_assert(2_km / 2_kmph == 1_h);
|
static_assert(2km / 2kmph == 1h);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@@ -43,23 +43,23 @@ namespace {
|
|||||||
|
|
||||||
// time
|
// time
|
||||||
|
|
||||||
static_assert(1_h == 3600_s);
|
static_assert(1h == 3600s);
|
||||||
|
|
||||||
// length
|
// length
|
||||||
|
|
||||||
static_assert(1_km == 1000_m);
|
static_assert(1km == 1000m);
|
||||||
static_assert(1_m == 100_cm);
|
static_assert(1m == 100cm);
|
||||||
static_assert(1_m == 1000_mm);
|
static_assert(1m == 1000mm);
|
||||||
static_assert(1_km + 1_m == 1001_m);
|
static_assert(1km + 1m == 1001m);
|
||||||
static_assert(10_km / 5_km == 2);
|
static_assert(10km / 5km == 2);
|
||||||
static_assert(10_km / 2 == 5_km);
|
static_assert(10km / 2 == 5km);
|
||||||
|
|
||||||
static_assert(1_yd == 0.9144_m);
|
static_assert(1yd == 0.9144m);
|
||||||
static_assert(1_yd == 3_ft);
|
static_assert(1yd == 3ft);
|
||||||
static_assert(1_ft == 12_in);
|
static_assert(1ft == 12in);
|
||||||
static_assert(1_mi == 1760_yd);
|
static_assert(1mi == 1760yd);
|
||||||
|
|
||||||
// static_assert(5_in + 8_cm == 207_mm);
|
// static_assert(5in + 8cm == 207mm);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -67,48 +67,38 @@ namespace {
|
|||||||
|
|
||||||
// frequency
|
// frequency
|
||||||
|
|
||||||
static_assert(2 / 1_s == 2_Hz);
|
static_assert(2 / 1s == 2Hz);
|
||||||
static_assert(1000 / 1_s == 1_kHz);
|
static_assert(1000 / 1s == 1kHz);
|
||||||
static_assert(1 / 1_ms == 1_kHz);
|
static_assert(1 / 1ms == 1kHz);
|
||||||
static_assert(3.2_GHz == 3'200'000'000_Hz);
|
static_assert(3.2GHz == 3'200'000'000Hz);
|
||||||
// static_assert(10_Hz * 1_min == 600);
|
// static_assert(10hz * 1min == 600);
|
||||||
|
|
||||||
// velocity
|
// velocity
|
||||||
|
|
||||||
static_assert(std::is_same_v<decltype(1_km / 1_s), quantity<unit<dimension_velocity, ratio<1000, 1>>, std::int64_t>>);
|
static_assert(std::is_same_v<decltype(1km / 1s), quantity<unit<dimension_velocity, ratio<1000, 1>>, std::int64_t>>);
|
||||||
|
|
||||||
static_assert(10_m / 5_s == 2_mps);
|
static_assert(10m / 5s == 2mps);
|
||||||
static_assert(10 / 5_s * 1_m == 2_mps);
|
static_assert(10 / 5s * 1m == 2mps);
|
||||||
static_assert(1_km / 1_s == 1000_mps);
|
static_assert(1km / 1s == 1000mps);
|
||||||
// static_assert(1_km / 1_h == 1_kmph); // should not compile
|
// static_assert(1km / 1h == 1kmph); // should not compile
|
||||||
static_assert(1.0_km / 1_h == 1_kmph);
|
static_assert(1.0km / 1h == 1kmph);
|
||||||
static_assert(1000.0_m / 3600.0_s == 1_kmph);
|
static_assert(1000.0m / 3600.0s == 1kmph);
|
||||||
|
|
||||||
static_assert(10.0_mi / 2_h == 5_mph);
|
static_assert(10.0mi / 2h == 5mph);
|
||||||
|
|
||||||
static_assert(2_kmph * 2_h == 4_km);
|
static_assert(2kmph * 2h == 4km);
|
||||||
// static_assert(2_kmph * 15_min == 500_m); // should not compile
|
// static_assert(2kmph * 15min == 500m); // should not compile
|
||||||
static_assert(2_kmph * 15.0_min == 500_m);
|
static_assert(2kmph * 15.0min == 500m);
|
||||||
static_assert(2.0_kmph * 15_min == 500_m);
|
static_assert(2.0kmph * 15min == 500m);
|
||||||
|
|
||||||
static_assert(2_km / 2_kmph == 1_h);
|
static_assert(2km / 2kmph == 1h);
|
||||||
// static_assert(2000_m / 2_kmph == 1_h); // should not compile
|
// static_assert(2000m / 2kmph == 1h); // should not compile
|
||||||
static_assert(quantity_cast<quantity<kilometer, int>>(2000_m) / 2_kmph == 1_h);
|
static_assert(quantity_cast<quantity<kilometer, int>>(2000m) / 2kmph == 1h);
|
||||||
|
|
||||||
// area
|
// area
|
||||||
|
|
||||||
static_assert(1_m * 1_m == 1_sq_m);
|
static_assert(1m * 1m == 1sq_m);
|
||||||
static_assert(10_km * 10_km == 100_sq_km);
|
static_assert(10km * 10km == 100sq_km);
|
||||||
static_assert(1_sq_m == 10'000_sq_cm);
|
static_assert(1sq_m == 10'000sq_cm);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// amplitude spectral density
|
|
||||||
|
|
||||||
// struct dimension_amplitude_spectral_density : make_dimension_t<exp<dim_voltage, 1>, exp<dim_frequency, ratio(-1, 2)>> {};
|
|
||||||
// template<> struct downcasting_traits<downcast_from<dimension_amplitude_spectral_density>> : downcast_to<dimension_amplitude_spectral_density> {};
|
|
||||||
//
|
|
||||||
// struct volt_per_sq_hertz : derived_unit<dimension_amplitude_spectral_density, meter, second> {};
|
|
||||||
// template<> struct downcasting_traits<downcast_from<meter_per_second>> : downcast_to<meter_per_second> {};
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
Reference in New Issue
Block a user