Skip to content

Conversation

@StephanTLavavej
Copy link
Member

@StephanTLavavej StephanTLavavej commented Mar 28, 2021

Related to #1749 - we should avoid using concepts when __cpp_lib_concepts isn't defined.

  • Cleanup: When performing SFINAE in default template arguments, use class = void_t<decltype(EXPRESSION)> for consistency (and shorter mangled names, although that doesn't really matter). This is still different than the most common form of enable_if_t<CONDITION, int> = 0 SFINAE which handles multiple overloads with the same signature, but that should be ok.
  • Cleanup: Update the comments about ICU/IANA. Thanks to @mattjohnsonpint for explaining what's happening here in <chrono>: Should divergence between ICU and IANA be reported? #1786.
  • hh_mm_ss can static_assert _Is_duration_v.
    • This is consistent with time_point:

      STL/stl/inc/chrono

      Lines 198 to 206 in 6aed1a6

      template <class _Clock, class _Duration = typename _Clock::duration>
      class time_point { // represents a point in time
      public:
      using clock = _Clock;
      using duration = _Duration;
      using rep = typename _Duration::rep;
      using period = typename _Duration::period;
      static_assert(_Is_duration_v<_Duration>, "duration must be an instance of std::duration");
  • Cleanup: The static_assert _Is_duration_v messages now say "mandates".
    • time_point was talking about std::duration which isn't a thing! 😹
  • Reimplement clock_time_conversion Constraints/Mandates.
    • Thanks to @MattStephanson for help decoding the WP here (see [time.clock.cast.sys] and [time.clock.cast.utc] reuse "Duration" confusingly cplusplus/draft#4564).
    • This implements the Standardese more precisely - e.g. WG21-N4885 [time.clock.cast.sys]/1 "Constraints: SourceClock::to_sys(t) is well-formed." isn't concerned about the return type, only /2 "Mandates: SourceClock::to_sys(t) returns a sys_time<Duration>" is.
    • The part of the Mandates that says "where Duration is a valid chrono::duration specialization" is enforced by time_point itself (which we're going to instantiate while attempting to return it).
    • We need _SourceClock2 and _DestClock2 as an extra layer of indirection because these template parameters belong to the struct instead of the function.
  • Rewrite clock_cast metaprogramming.
    • This uses @CaseyCarter's "choice" approach from ranges. Here's it's almost too high-powered (compared to just directly testing these things in clock_cast's function body), but not quite - we need to implement [time.clock.cast.fn]/1 "Constraints: At least one of the following clock time conversion expressions is well-formed" (which wasn't previously implemented as a constraint - instead it was a static_assert which would be a Mandates), so the "choice" tech lets us reuse that work.

@StephanTLavavej StephanTLavavej added cxx20 C++20 feature chrono C++20 chrono labels Mar 28, 2021
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner March 28, 2021 02:57
@StephanTLavavej StephanTLavavej merged commit dde4623 into microsoft:feature/chrono Mar 29, 2021
@StephanTLavavej StephanTLavavej deleted the chrono_concepts branch March 29, 2021 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chrono C++20 chrono cxx20 C++20 feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants