forked from mpusz/mp-units
docs: code samples modernized
This commit is contained in:
@@ -69,8 +69,10 @@ performed without sacrificing accuracy. Please see the below example for a quick
|
||||
=== "C++ modules"
|
||||
|
||||
```cpp
|
||||
#include <format>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <print>
|
||||
import mp_units;
|
||||
|
||||
using namespace mp_units;
|
||||
@@ -97,10 +99,10 @@ performed without sacrificing accuracy. Please see the below example for a quick
|
||||
std::cout << v1 << '\n'; // 110 km/h
|
||||
std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h
|
||||
std::cout << std::format("{:*^10}\n", v3); // *110 km/h*
|
||||
std::cout << std::format("{:%N in %U}\n", v4); // 70 in mi/h
|
||||
std::cout << std::format("{:{%N:.2f}%?%U}\n", v5); // 30.56 in m/s
|
||||
std::cout << std::format("{:{%N:.2f}%?{%U:n}}\n", v6); // 31.29 in m s⁻¹
|
||||
std::cout << std::format("{:%N}\n", v7); // 31
|
||||
std::println("{:%N in %U}", v4); // 70 in mi/h
|
||||
std::println("{:{%N:.2f}%?%U}", v5); // 30.56 m/s
|
||||
std::println("{:{%N:.2f}%?{%U:n}}", v6); // 31.29 m s⁻¹
|
||||
std::println("{:%N}", v7); // 31
|
||||
}
|
||||
```
|
||||
|
||||
@@ -112,8 +114,10 @@ performed without sacrificing accuracy. Please see the below example for a quick
|
||||
#include <mp-units/systems/international/international.h>
|
||||
#include <mp-units/systems/isq/isq.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <format>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <print>
|
||||
|
||||
using namespace mp_units;
|
||||
|
||||
@@ -139,14 +143,14 @@ performed without sacrificing accuracy. Please see the below example for a quick
|
||||
std::cout << v1 << '\n'; // 110 km/h
|
||||
std::cout << std::setw(10) << std::setfill('*') << v2 << '\n'; // ***70 mi/h
|
||||
std::cout << std::format("{:*^10}\n", v3); // *110 km/h*
|
||||
std::cout << std::format("{:%N in %U}\n", v4); // 70 in mi/h
|
||||
std::cout << std::format("{:{%N:.2f}%?%U}\n", v5); // 30.56 in m/s
|
||||
std::cout << std::format("{:{%N:.2f}%?{%U:n}}\n", v6); // 31.29 in m s⁻¹
|
||||
std::cout << std::format("{:%N}\n", v7); // 31
|
||||
std::println("{:%N in %U}", v4); // 70 in mi/h
|
||||
std::println("{:{%N:.2f}%?%U}", v5); // 30.56 m/s
|
||||
std::println("{:{%N:.2f}%?{%U:n}}", v6); // 31.29 m s⁻¹
|
||||
std::println("{:%N}", v7); // 31
|
||||
}
|
||||
```
|
||||
|
||||
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/Tsesa1Pvq)"
|
||||
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/hWzxf1j1M)"
|
||||
|
||||
!!! note
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ This introduces an additional type-safety.
|
||||
=== "C++ modules"
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
#include <print>
|
||||
import mp_units;
|
||||
|
||||
int main()
|
||||
@@ -157,32 +157,32 @@ This introduces an additional type-safety.
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
using namespace mp_units::usc::unit_symbols;
|
||||
|
||||
|
||||
quantity_point temp{20. * deg_C};
|
||||
std::cout << "Temperature: "
|
||||
<< temp.quantity_from_zero() << " ("
|
||||
<< temp.in(deg_F).quantity_from_zero() << ")\n";
|
||||
std::println("Temperature: {} ({})",
|
||||
temp.quantity_from_zero(),
|
||||
temp.in(deg_F).quantity_from_zero());
|
||||
}
|
||||
```
|
||||
|
||||
=== "Header files"
|
||||
|
||||
```cpp
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <mp-units/systems/usc/usc.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <print>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
using namespace mp_units::usc::unit_symbols;
|
||||
|
||||
|
||||
quantity_point temp{20. * deg_C};
|
||||
std::cout << "Temperature: "
|
||||
<< temp.quantity_from_zero() << " ("
|
||||
<< temp.in(deg_F).quantity_from_zero() << ")\n";
|
||||
std::println("Temperature: {} ({})",
|
||||
temp.quantity_from_zero(),
|
||||
temp.in(deg_F).quantity_from_zero());
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user