Date: Wed, 6 Nov 2024 16:20:40 +0100
The static member functions "to_time_t" and "from_time_t" in
"std::chrono::system_clock" should be marked constexpr.
Most datetime libraries support some kind of conversion function between
their own types and time_t, which practically allows to convert any
datetime type (via time_t) to std::chrono::system_clock.
However the conversion from and to time_t in std::chrono::system_clock
isn't constexpr and so can't be used e.g. with a static_assert, which I
like to use in some places for some basic "testing" without having to run
separate unit tests.
Might not be the best use case and there might be other ones but even
though I'm not too familiar with standardization I assume it should be a
rather small change.
And with "std::chrono::time_point" itself having constexpr constructors I
don't see any reason to not have constexpr conversion.
- Jonas
"std::chrono::system_clock" should be marked constexpr.
Most datetime libraries support some kind of conversion function between
their own types and time_t, which practically allows to convert any
datetime type (via time_t) to std::chrono::system_clock.
However the conversion from and to time_t in std::chrono::system_clock
isn't constexpr and so can't be used e.g. with a static_assert, which I
like to use in some places for some basic "testing" without having to run
separate unit tests.
Might not be the best use case and there might be other ones but even
though I'm not too familiar with standardization I assume it should be a
rather small change.
And with "std::chrono::time_point" itself having constexpr constructors I
don't see any reason to not have constexpr conversion.
- Jonas
Received on 2024-11-06 15:20:54