Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to assign zero to std::chrono::nanoseconds

Tags:

c++

c++11

chrono

Is there a way to assign zero to a duration of type std::chrono::nanoseconds? I tried duration::zero but it failed.

like image 327
user3639557 Avatar asked May 14 '15 11:05

user3639557


1 Answers

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;
like image 124
Barry Avatar answered Nov 13 '22 17:11

Barry