简体   繁体   English

如果 d > 255,为什么 std::chrono::day 存储值未指定

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

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

A std::chrono::day storing d.一个 std::chrono::day 存储 d. If d > 255, the stored value is unspecified.如果 d > 255,则未指定存储值。

What is the rationale behind this limit ?这个限制背后的原理是什么?

The literal can't store more than std::chrono::day itself can, which is 0 - 255 .文字不能存储超过std::chrono::day本身可以存储的数量,即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.这允许将其实现为 1 字节数据类型,因为它通常只存储 1 到 31 之间的值就足够了。

If you're looking for a data type to store a duration of an arbitrary number of days use std::chrono::days instead.如果您正在寻找一种数据类型来存储任意天数的持续时间,请改用std::chrono::days

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM