Damien Garrido
Damien Garrido

Reputation: 158

Why std::chrono::day stored value is unspecified if d > 255

Quoted from std::literals::chrono_literals::operator""d

A std::chrono::day storing d. If d > 255, the stored value is unspecified.

What is the rationale behind this limit ?

Upvotes: 3

Views: 107

Answers (1)

Alan Birtles
Alan Birtles

Reputation: 36379

The literal can't store more than std::chrono::day itself can, which is 0-255. This allows it to be implemented as a 1 byte data type, which as it usually will only store values between 1 and 31 is sufficient.

If you're looking for a data type to store a duration of an arbitrary number of days use std::chrono::days instead.

Upvotes: 5

Related Questions