简体   繁体   English

为什么std :: chrono :: system_clock :: to_time_t()不是constexpr?

[英]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_tstd::chrono::system_clock::from_time_t ),列为staticnoexcept但不是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_pointduration基本上所有操作都是constexpr (包括duration_casttime_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.

相关问题 为什么此代码在std :: chrono :: system_clock上不起作用? - Why isnt't this code with std::chrono::system_clock working? std::chrono::system_clock 和 C 时间 - std::chrono::system_clock and C time 二进制&#39;&gt; =&#39;:&#39;std :: chrono :: system_clock :: time_point&#39; - binary '>=': 'std::chrono::system_clock::time_point' boost :: serialize和std :: chrono :: system_clock :: time_point - boost::serialize and std::chrono::system_clock::time_point 时间差与std :: chrono :: system_clock / std :: chrono :: high_resolution_clock - time differences with std::chrono::system_clock / std::chrono::high_resolution_clock 是 std::atomic <std::optional<std::chrono::time_point<std::chrono::system_clock> &gt;&gt; 有效/安全? </std::optional<std::chrono::time_point<std::chrono::system_clock> - Is std::atomic<std::optional<std::chrono::time_point<std::chrono::system_clock>>> valid/safe? 使用system_clock :: to_time_t的持续性time_t警告 - Persistent time_t warning using system_clock::to_time_t std :: chrono :: system_clock和持续时间<double> - std::chrono::system_clock and duration<double> std::chrono::system_clock::now() 序列化 - std::chrono::system_clock::now() serialization 如何从std :: chrono :: system_clock :: time_point.time_since_epoch()。count()获取std :: chrono :: system_clock :: time_point? - How to get std::chrono::system_clock::time_point from std::chrono::system_clock::time_point.time_since_epoch().count()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM