docs: quick start example updated with the latest changes

This commit is contained in:
Mateusz Pusz
2020-12-29 11:45:38 +01:00
parent a365bca07c
commit 1cc47cbab4
2 changed files with 32 additions and 20 deletions

View File

@@ -61,9 +61,9 @@ and dimensional analysis can be performed without sacrificing on accuracy. Pleas
the below example for a quick preview of basic library features:
```cpp
#include <units/format.h>
#include <units/physical/si/derived/speed.h>
#include <units/physical/si/international/derived/speed.h>
#include <units/format.h>
#include <units/quantity_io.h>
#include <iostream>
@@ -77,16 +77,22 @@ constexpr Speed auto avg_speed(Length auto d, Time auto t)
int main()
{
using namespace units::physical::si::literals;
Speed auto v1 = avg_speed(220_q_km, 2_q_h);
Speed auto v2 = avg_speed(si::length<si::international::mile>(140), si::time<si::hour>(2));
Speed auto v3 = quantity_cast<si::metre_per_second>(v2);
Speed auto v4 = quantity_cast<int>(v3);
using namespace units::physical::si::unit_constants;
std::cout << v1 << '\n'; // 110 km/h
std::cout << v2 << '\n'; // 70 mi/h
std::cout << v3 << '\n'; // 31.2928 m/s
std::cout << v4 << '\n'; // 31 m/s
constexpr Speed auto v1 = 110 * km / h;
constexpr Speed auto v2 = avg_speed(220_q_km, 2_q_h);
constexpr Speed auto v3 = avg_speed(si::length<si::international::mile>(140), si::time<si::hour>(2));
constexpr Speed auto v4 = quantity_cast<si::speed<si::metre_per_second>>(v2);
constexpr Speed auto v5 = quantity_cast<si::metre_per_second>(v3);
constexpr Speed auto v6 = quantity_cast<int>(v5);
std::cout << v1 << '\n'; // 110 km/h
std::cout << fmt::format("{}", v2) << '\n'; // 110 km/h
std::cout << fmt::format("{:*^14}", v3) << '\n'; // ***70 mi/h****
std::cout << fmt::format("{:%Q in %q}", v4) << '\n'; // 30.5556 in m/s
std::cout << fmt::format("{0:%Q} in {0:%q}", v5) << '\n'; // 31.2928 in m/s
std::cout << fmt::format("{:%Q}", v6) << '\n'; // 31
}
```
_Try it on the [Compiler Explorer](https://godbolt.org/z/8dh4cv)._
_Try it on the [Compiler Explorer](https://godbolt.org/z/eca49d)._

View File

@@ -37,9 +37,9 @@ but still easy to use interface where all unit conversions and dimensional analy
performed without sacrificing on accuracy. Please see the below example for a quick preview
of basic library features::
#include <units/format.h>
#include <units/physical/si/derived/speed.h>
#include <units/physical/si/international/derived/speed.h>
#include <units/format.h>
#include <units/quantity_io.h>
#include <iostream>
@@ -53,20 +53,26 @@ of basic library features::
int main()
{
using namespace units::physical::si::literals;
Speed auto v1 = avg_speed(220_q_km, 2_q_h);
Speed auto v2 = avg_speed(si::length<si::international::mile>(140), si::time<si::hour>(2));
Speed auto v3 = quantity_cast<si::metre_per_second>(v2);
Speed auto v4 = quantity_cast<int>(v3);
using namespace units::physical::si::unit_constants;
std::cout << v1 << '\n'; // 110 km/h
std::cout << v2 << '\n'; // 70 mi/h
std::cout << v3 << '\n'; // 31.2928 m/s
std::cout << v4 << '\n'; // 31 m/s
constexpr Speed auto v1 = 110 * km / h;
constexpr Speed auto v2 = avg_speed(220_q_km, 2_q_h);
constexpr Speed auto v3 = avg_speed(si::length<si::international::mile>(140), si::time<si::hour>(2));
constexpr Speed auto v4 = quantity_cast<si::speed<si::metre_per_second>>(v2);
constexpr Speed auto v5 = quantity_cast<si::metre_per_second>(v3);
constexpr Speed auto v6 = quantity_cast<int>(v5);
std::cout << v1 << '\n'; // 110 km/h
std::cout << fmt::format("{}", v2) << '\n'; // 110 km/h
std::cout << fmt::format("{:*^14}", v3) << '\n'; // ***70 mi/h****
std::cout << fmt::format("{:%Q in %q}", v4) << '\n'; // 30.5556 in m/s
std::cout << fmt::format("{0:%Q} in {0:%q}", v5) << '\n'; // 31.2928 in m/s
std::cout << fmt::format("{:%Q}", v6) << '\n'; // 31
}
.. admonition:: Try it on Compiler Explorer
`Example #2 <https://godbolt.org/z/8dh4cv>`_
`Example #2 <https://godbolt.org/z/eca49d>`_
.. seealso::