From d8ce013ab670e8ffa2e2328e77d9a11d6289edac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 14 Mar 2024 19:09:30 +0100 Subject: [PATCH] doc: I realized a much nicer way of converting to/from Nanoseconds. --- doc/snippets/Math-stl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/snippets/Math-stl.cpp b/doc/snippets/Math-stl.cpp index 03668ad61..d5d903261 100644 --- a/doc/snippets/Math-stl.cpp +++ b/doc/snippets/Math-stl.cpp @@ -106,13 +106,17 @@ static_cast(b); /* [Nanoseconds-usage-time] */ Nanoseconds a1{std::time(nullptr)}; // wrong, the input is seconds Nanoseconds a2{std::time(nullptr)*1000000000ll}; // correct +Nanoseconds a3 = std::time(nullptr)*1.0_sec; // or, alternatively std::time_t b1(35.0_sec); // wrong, the input is nanoseconds std::time_t b2(35.0_sec/1000000000ll); // correct +std::time_t b3 = 35.0_sec/1.0_sec; // or, alternatively /* [Nanoseconds-usage-time] */ static_cast(a1); static_cast(a2); +static_cast(a3); static_cast(b1); static_cast(b2); +static_cast(b3); } #endif }