forked from mpusz/mp-units
refactor: op[U] for quantity and quantity_point replaced with .in(U)
Resolves #469
This commit is contained in:
@@ -61,7 +61,7 @@ constexpr auto speed_of_light_in_vacuum = 1 * si::si2019::speed_of_light_in_vacu
|
||||
|
||||
QuantityOf<isq::permittivity_of_vacuum> auto q = 1 / (permeability_of_vacuum * pow<2>(speed_of_light_in_vacuum));
|
||||
|
||||
std::cout << "permittivity of vacuum = " << q << " = " << q[F / m] << "\n";
|
||||
std::cout << "permittivity of vacuum = " << q << " = " << q.in(F / m) << "\n";
|
||||
```
|
||||
|
||||
The above first prints the following:
|
||||
@@ -99,18 +99,18 @@ std::cout << "in `GeV` and `c`:\n"
|
||||
<< "m = " << m1 << "\n"
|
||||
<< "E = " << E << "\n";
|
||||
|
||||
const auto p2 = p1[GeV / (m / s)];
|
||||
const auto m2 = m1[GeV / pow<2>(m / s)];
|
||||
const auto E2 = total_energy(p2, m2, c)[GeV];
|
||||
const auto p2 = p1.in(GeV / (m / s));
|
||||
const auto m2 = m1.in(GeV / pow<2>(m / s));
|
||||
const auto E2 = total_energy(p2, m2, c).in(GeV);
|
||||
|
||||
std::cout << "\nin `GeV`:\n"
|
||||
<< "p = " << p2 << "\n"
|
||||
<< "m = " << m2 << "\n"
|
||||
<< "E = " << E2 << "\n";
|
||||
|
||||
const auto p3 = p1[kg * m / s];
|
||||
const auto m3 = m1[kg];
|
||||
const auto E3 = total_energy(p3, m3, c)[J];
|
||||
const auto p3 = p1.in(kg * m / s);
|
||||
const auto m3 = m1.in(kg);
|
||||
const auto E3 = total_energy(p3, m3, c).in(J);
|
||||
|
||||
std::cout << "\nin SI base units:\n"
|
||||
<< "p = " << p3 << "\n"
|
||||
|
||||
@@ -264,7 +264,7 @@ using namespace mp_units::si::unit_symbols;
|
||||
auto speed = 60. * isq::speed[km / h];
|
||||
auto duration = 8 * s;
|
||||
auto acceleration = speed / duration;
|
||||
std::cout << "acceleration: " << acceleration << " (" << acceleration[m / s2] << ")\n";
|
||||
std::cout << "acceleration: " << acceleration << " (" << acceleration.in(m / s2) << ")\n";
|
||||
```
|
||||
|
||||
The `acceleration`, being the result of the above code, has the following type
|
||||
|
||||
@@ -72,7 +72,7 @@ int main()
|
||||
|
||||
std::cout << "A car driving " << distance << " in " << duration
|
||||
<< " has an average speed of " << speed
|
||||
<< " (" << speed[km / h] << ")\n";
|
||||
<< " (" << speed.in(km / h) << ")\n";
|
||||
}
|
||||
```
|
||||
|
||||
@@ -82,7 +82,7 @@ The code above prints:
|
||||
A car driving 110 km in 2 h has an average speed of 15.2778 m/s (55 km/h)
|
||||
```
|
||||
|
||||
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/4zecYqn5z)"
|
||||
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/zWe8ecf93)"
|
||||
|
||||
|
||||
### Easy to understand compilation error messages
|
||||
@@ -146,7 +146,7 @@ int main()
|
||||
|
||||
std::cout << "A car driving " << distance << " in " << duration
|
||||
<< " has an average speed of " << speed
|
||||
<< " (" << speed[km / h] << ")\n";
|
||||
<< " (" << speed.in(km / h) << ")\n";
|
||||
}
|
||||
```
|
||||
|
||||
@@ -154,7 +154,7 @@ int main()
|
||||
A car driving 110 km in 2 h has an average speed of 15.2778 m/s (55 km/h)
|
||||
```
|
||||
|
||||
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/jhfWjGadz)"
|
||||
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/q3PzMzqsh)"
|
||||
|
||||
In case we will accidentally make the same calculation error as before, this time, we will
|
||||
get a bit longer error message also containing information about the quantity type:
|
||||
|
||||
@@ -76,9 +76,9 @@ the following:
|
||||
```cpp
|
||||
auto q1 = 42 * W;
|
||||
std::cout << q1 << "\n";
|
||||
std::cout << q1[J / s] << "\n";
|
||||
std::cout << q1[N * m / s] << "\n";
|
||||
std::cout << q1[kg * m2 / s3] << "\n";
|
||||
std::cout << q1.in(J / s) << "\n";
|
||||
std::cout << q1.in(N * m / s) << "\n";
|
||||
std::cout << q1.in(kg * m2 / s3) << "\n";
|
||||
```
|
||||
|
||||
prints:
|
||||
|
||||
@@ -44,7 +44,7 @@ associated with this quantity.
|
||||
before passing it to the text output:
|
||||
|
||||
```cpp
|
||||
std::cout << v1[km / h] << '\n'; // 110 km/h
|
||||
std::cout << v1.in(km / h) << '\n'; // 110 km/h
|
||||
std::cout << value_cast<m / s>(v1) << '\n'; // 30.5556 m/s
|
||||
```
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
```cpp
|
||||
auto q1 = 5 * km;
|
||||
std::cout << q1[m] << '\n';
|
||||
std::cout << q1.in(m) << '\n';
|
||||
quantity<si::metre, int> q2 = q1;
|
||||
```
|
||||
|
||||
@@ -23,7 +23,7 @@ In case a user would like to perform an opposite transformation:
|
||||
|
||||
```cpp
|
||||
auto q1 = 5 * m;
|
||||
std::cout << q1[km] << '\n';
|
||||
std::cout << q1.in(km) << '\n';
|
||||
quantity<si::kilo<si::metre>, int> q2 = q1;
|
||||
```
|
||||
|
||||
@@ -34,7 +34,7 @@ representation type:
|
||||
|
||||
```cpp
|
||||
auto q1 = 5. * m;
|
||||
std::cout << q1[km] << '\n';
|
||||
std::cout << q1.in(km) << '\n';
|
||||
quantity<si::kilo<si::metre>> q2 = q1;
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user