mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-06 05:34:27 +02:00
docs: auto
replaced with type placeholders in code examples
This commit is contained in:
@@ -13,7 +13,7 @@ The quantity is created by multiplying a number with a predefined unit:
|
|||||||
|
|
||||||
using namespace mp_units;
|
using namespace mp_units;
|
||||||
|
|
||||||
auto q = 42 * si::metre;
|
quantity q = 42 * si::metre;
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! note
|
!!! note
|
||||||
@@ -30,7 +30,7 @@ an optional unit symbol:
|
|||||||
using namespace mp_units;
|
using namespace mp_units;
|
||||||
using namespace mp_units::si::unit_symbols;
|
using namespace mp_units::si::unit_symbols;
|
||||||
|
|
||||||
auto q = 42 * m;
|
quantity q = 42 * m;
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! note
|
!!! note
|
||||||
@@ -48,7 +48,7 @@ function:
|
|||||||
|
|
||||||
using namespace mp_units;
|
using namespace mp_units;
|
||||||
|
|
||||||
auto q = make_quantity<si::metre>(42);
|
quantity q = make_quantity<si::metre>(42);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ auto q = make_quantity<si::metre>(42);
|
|||||||
Sometimes it might be awkward to type some derived units:
|
Sometimes it might be awkward to type some derived units:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto speed = 60 * (km / h);
|
quantity speed = 60 * (km / h);
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! note
|
!!! note
|
||||||
@@ -70,7 +70,7 @@ wrapper for it with:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
constexpr auto kmph = km / h;
|
constexpr auto kmph = km / h;
|
||||||
auto speed = 60 * kmph;
|
quantity speed = 60 * kmph;
|
||||||
```
|
```
|
||||||
|
|
||||||
or even:
|
or even:
|
||||||
@@ -79,7 +79,7 @@ or even:
|
|||||||
constexpr auto kilometre = si::kilo<si::metre>;
|
constexpr auto kilometre = si::kilo<si::metre>;
|
||||||
constexpr auto kilometre_per_hour = kilometre / si::hour;
|
constexpr auto kilometre_per_hour = kilometre / si::hour;
|
||||||
constexpr auto kmph = kilometre_per_hour;
|
constexpr auto kmph = kilometre_per_hour;
|
||||||
auto speed = 60 * kmph;
|
quantity speed = 60 * kmph;
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! note
|
!!! note
|
||||||
|
@@ -66,9 +66,9 @@ int main()
|
|||||||
{
|
{
|
||||||
using namespace mp_units::si::unit_symbols;
|
using namespace mp_units::si::unit_symbols;
|
||||||
|
|
||||||
const auto distance = 110 * km;
|
const quantity distance = 110 * km;
|
||||||
const auto duration = 2 * h;
|
const quantity duration = 2 * h;
|
||||||
const auto speed = avg_speed(distance, duration);
|
const quantity speed = avg_speed(distance, duration);
|
||||||
|
|
||||||
std::cout << "A car driving " << distance << " in " << duration
|
std::cout << "A car driving " << distance << " in " << duration
|
||||||
<< " has an average speed of " << speed
|
<< " has an average speed of " << speed
|
||||||
@@ -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)
|
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/W6Ej7aqxj)"
|
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/4zecYqn5z)"
|
||||||
|
|
||||||
|
|
||||||
### Easy to understand compilation error messages
|
### Easy to understand compilation error messages
|
||||||
@@ -140,9 +140,9 @@ constexpr quantity<isq::speed[m / s]> avg_speed(quantity<isq::length[m]> d,
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
const auto distance = isq::distance(110 * km);
|
const quantity distance = isq::distance(110 * km);
|
||||||
const auto duration = isq::time(2 * h);
|
const quantity duration = isq::time(2 * h);
|
||||||
const auto speed = avg_speed(distance, duration);
|
const quantity speed = avg_speed(distance, duration);
|
||||||
|
|
||||||
std::cout << "A car driving " << distance << " in " << duration
|
std::cout << "A car driving " << distance << " in " << duration
|
||||||
<< " has an average speed of " << speed
|
<< " has an average speed of " << speed
|
||||||
@@ -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)
|
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/98YP8j9b4)"
|
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/jhfWjGadz)"
|
||||||
|
|
||||||
In case we will accidentally make the same calculation error as before, this time, we will
|
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:
|
get a bit longer error message also containing information about the quantity type:
|
||||||
|
Reference in New Issue
Block a user