Is there a way to assign zero to a duration of type std::chrono::nanoseconds? I tried duration::zero but it failed.
There is a zero() function:
std::chrono::nanoseconds dur;
// ...
dur = std::chrono::nanoseconds::zero();
Or you could assign it to a temporary of type nanoseconds explicitly constructed with 0:
dur = std::chrono::nanoseconds{0};
which is what zero() returns too.
Lastly, if you're using a compiler that supports it, there is just:
// requires either "using namespace std::chrono_literals;" or "using namespace std::chrono;"
dur = 0ns;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With