mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 05:04:27 +02:00
docs: quick start example updated with fmt
Compiler Explorer finaly does not time out of fmt library :-)
This commit is contained in:
@@ -55,6 +55,7 @@ the below example for a quick preview of basic library features:
|
|||||||
```cpp
|
```cpp
|
||||||
#include <units/physical/si/speed.h>
|
#include <units/physical/si/speed.h>
|
||||||
#include <units/physical/international/speed.h>
|
#include <units/physical/international/speed.h>
|
||||||
|
#include <units/format.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace units::physical;
|
using namespace units::physical;
|
||||||
@@ -73,10 +74,10 @@ int main()
|
|||||||
Speed auto v4 = quantity_cast<int>(v3);
|
Speed auto v4 = quantity_cast<int>(v3);
|
||||||
|
|
||||||
std::cout << v1 << '\n'; // 110 km/h
|
std::cout << v1 << '\n'; // 110 km/h
|
||||||
std::cout << v2 << '\n'; // 70 mi/h
|
std::cout << fmt::format("{}", v2) << '\n'; // 70 mi/h
|
||||||
std::cout << v3 << '\n'; // 31.2928 m/s
|
std::cout << fmt::format("{:%Q in %q}", v3) << '\n'; // 31.2928 in m/s
|
||||||
std::cout << v4 << '\n'; // 31 m/s
|
std::cout << fmt::format("{:%Q}", v4) << '\n'; // 31
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
_Try it on the [Compiler Explorer](https://godbolt.org/z/f-f6y6)._
|
_Try it on the [Compiler Explorer](https://godbolt.org/z/xE91TY)._
|
||||||
|
@@ -33,6 +33,7 @@ of basic library features::
|
|||||||
|
|
||||||
#include <units/physical/si/speed.h>
|
#include <units/physical/si/speed.h>
|
||||||
#include <units/physical/international/speed.h>
|
#include <units/physical/international/speed.h>
|
||||||
|
#include <units/format.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace units::physical;
|
using namespace units::physical;
|
||||||
@@ -51,14 +52,14 @@ of basic library features::
|
|||||||
Speed auto v4 = quantity_cast<int>(v3);
|
Speed auto v4 = quantity_cast<int>(v3);
|
||||||
|
|
||||||
std::cout << v1 << '\n'; // 110 km/h
|
std::cout << v1 << '\n'; // 110 km/h
|
||||||
std::cout << v2 << '\n'; // 70 mi/h
|
std::cout << fmt::format("{}", v2) << '\n'; // 70 mi/h
|
||||||
std::cout << v3 << '\n'; // 31.2928 m/s
|
std::cout << fmt::format("{:%Q in %q}", v3) << '\n'; // 31.2928 in m/s
|
||||||
std::cout << v4 << '\n'; // 31 m/s
|
std::cout << fmt::format("{:%Q}", v4) << '\n'; // 31
|
||||||
}
|
}
|
||||||
|
|
||||||
.. admonition:: Try it on Compiler Explorer
|
.. admonition:: Try it on Compiler Explorer
|
||||||
|
|
||||||
`Example #2 <https://godbolt.org/z/f-f6y6>`_
|
`Example #2 <https://godbolt.org/z/xE91TY>`_
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user