[英]Why is std::chrono::system_clock::to_time_t() not constexpr?
The C++ standard (github.com/cplusplus/draft) has the time_t
conversion functions ( std::chrono::system_clock::to_time_t
and std::chrono::system_clock::from_time_t
) for listed as static
and noexcept
but not constexpr
. C ++标准(github.com/cplusplus/draft)具有
time_t
转换函数( std::chrono::system_clock::to_time_t
和std::chrono::system_clock::from_time_t
),列为static
和noexcept
但不是constexpr
。
Given that essentially all of the operations on time_point
and duration
are constexpr
(including duration_cast
and time_point_cast
), I can't think of any reason to exclude them. 鉴于
time_point
和duration
基本上所有操作都是constexpr
(包括duration_cast
和time_point_cast
),我想不出有任何理由要排除它们。 A quick inspection of the libstdc++ sources on my local machine confirms that these functions are implemented as simple duration/time_point casts. 快速检查本地计算机上的libstdc ++源代码确认这些函数是作为简单的duration / time_point强制转换实现的。
Is there any reason that these two functions should not be constexpr
? 是否有任何理由认为这两个功能不应该是
constexpr
? Is this just a case of "because no one proposed they should be"? 这只是“因为没有人提出他们应该”的情况吗?
Is this just a case of "because no one proposed they should be"?
这只是“因为没有人提出他们应该”的情况吗?
Yes, I think that is exactly right. 是的,我认为这是完全正确的。
I'm curious: Once you get a constexpr time_t
, what are you going to do with it? 我很好奇:一旦你得到一个
constexpr time_t
,你打算用它做什么? None of the C functions taking time_t
are constexpr
. 考虑
time_t
的C函数都不是constexpr
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.