mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-01 11:24:27 +02:00
refactor: example applications refactored to a new formatting syntax
This commit is contained in:
25
README.md
25
README.md
@@ -58,7 +58,7 @@ analysis and unit/quantity manipulation.
|
||||
Here is a small example of possible operations:
|
||||
|
||||
```cpp
|
||||
#include <mp-units/systems/si/si.h>
|
||||
import mp_units;
|
||||
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
@@ -66,7 +66,7 @@ using namespace mp_units::si::unit_symbols;
|
||||
// simple numeric operations
|
||||
static_assert(10 * km / 2 == 5 * km);
|
||||
|
||||
// unit conversions
|
||||
// conversions to common units
|
||||
static_assert(1 * h == 3600 * s);
|
||||
static_assert(1 * km + 1 * m == 1001 * m);
|
||||
|
||||
@@ -90,12 +90,9 @@ and dimensional analysis can be performed without sacrificing on runtime perform
|
||||
accuracy. Please see the below example for a quick preview of basic library features:
|
||||
|
||||
```cpp
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/systems/international/international.h>
|
||||
#include <mp-units/systems/isq/isq.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
import mp_units;
|
||||
|
||||
using namespace mp_units;
|
||||
|
||||
@@ -118,13 +115,13 @@ int main()
|
||||
constexpr quantity v6 = value_cast<m / s>(v4);
|
||||
constexpr quantity v7 = value_cast<int>(v6);
|
||||
|
||||
std::cout << v1 << '\n'; // 110 km/h
|
||||
std::cout << v2 << '\n'; // 70 mi/h
|
||||
std::cout << std::format("{}", v3) << '\n'; // 110 km/h
|
||||
std::cout << std::format("{:*^14}", v4) << '\n'; // ***70 mi/h****
|
||||
std::cout << std::format("{:%Q in %q}", v5) << '\n'; // 30.5556 in m/s
|
||||
std::cout << std::format("{0:%Q} in {0:%q}", v6) << '\n'; // 31.2928 in m/s
|
||||
std::cout << std::format("{:%Q}", v7) << '\n'; // 31
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user