Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

user-defined literals overloading in <chrono>

chrono takes user-defined literals to make it more convenient. For each literal, it has two overloading functions.

constexpr chrono::hours operator "" h(unsigned long long);
constexpr chrono::duration<unspecified , ratio<3600,1>> operator "" h(long double);

I'm confused by the second overloading function, i.e. the function with long double as parameter.

Why we need the second overloading? And what is unspecified?

like image 851
for_stack Avatar asked Mar 28 '26 07:03

for_stack


1 Answers

Both represent std::chrono::duration in hours. The first one forms an integer literal, the second one forms a floating-point literal. First one can represent tick count only, the second one can represent fractions of ticks.

like image 155
Ron Avatar answered Mar 29 '26 20:03

Ron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!