diff --git a/README.md b/README.md index 72d2f0b9..fd947432 100644 --- a/README.md +++ b/README.md @@ -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 #include #include -#include #include #include @@ -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(140), si::time(2)); - Speed auto v3 = quantity_cast(v2); - Speed auto v4 = quantity_cast(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(140), si::time(2)); + constexpr Speed auto v4 = quantity_cast>(v2); + constexpr Speed auto v5 = quantity_cast(v3); + constexpr Speed auto v6 = quantity_cast(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)._ diff --git a/docs/quick_start.rst b/docs/quick_start.rst index 351f6c30..929c87a1 100644 --- a/docs/quick_start.rst +++ b/docs/quick_start.rst @@ -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 #include #include - #include #include #include @@ -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(140), si::time(2)); - Speed auto v3 = quantity_cast(v2); - Speed auto v4 = quantity_cast(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(140), si::time(2)); + constexpr Speed auto v4 = quantity_cast>(v2); + constexpr Speed auto v5 = quantity_cast(v3); + constexpr Speed auto v6 = quantity_cast(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 `_ + `Example #2 `_ .. seealso::