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.
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. A quick inspection of the libstdc++ sources on my local machine confirms that these functions are implemented as simple duration/time_point casts.
Is there any reason that these two functions should not be constexpr? Is this just a case of "because no one proposed they should be"?
std::chrono::system_clock::now Returns a time point representing with the current point in time.
system_clock measures Unix Time (i.e., time since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds).
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? None of the C functions taking time_t are constexpr.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With