Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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"?

like image 238
marack Avatar asked Jan 23 '14 04:01

marack


People also ask

What does std :: Chrono :: System_clock :: now return?

std::chrono::system_clock::now Returns a time point representing with the current point in time.

Is System_clock UTC?

system_clock measures Unix Time (i.e., time since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds).


1 Answers

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.

like image 134
Howard Hinnant Avatar answered Oct 20 '22 17:10

Howard Hinnant