What is the proper way to get the count of ticks of a duration in C++1x

Viewed 131

I'm using C++ to develop my project and I used std::chrono.

I need to get a count of ticks of some duration, for example, I may need an integer 3600, which represents the count of second-ticks of one hour.

To get this integer, I can code as below:

int a = 3600; // 1 hour = 3600 sec
int b = std::chrono::duration_cast<std::chrono::seconds>(1h).count();
int c = (1h + 0s).count();

Obviously, each of these can give me a 3600. The first one is quite simple but I'd better add some comment to avoid the magic number 3600. The second one is quite clear but may I say it's really really too long? And the third one is not long, and + 0s could convert 1h into std::chrono::seconds automatically so I can get what I want, but is it kind of tricky?

So could you please tell me which one is the best in the view of the modern C++ or is there any better code than mine?

0 Answers
Related