Skip to content

<chrono>: Consider performing stricter checks in is_clock_v #5827

@frederick-vs-ja

Description

@frederick-vs-ja

Currently, MSVC STL only performs basic checks in std::chrono::is_clock(_v) as required by [time.traits.is.clock]/1.

_EXPORT_STD template <class _Clock>
_NO_SPECIALIZATIONS_OF_VARIABLE_TEMPLATES constexpr bool is_clock_v = requires {
typename _Clock::rep;
typename _Clock::period;
typename _Clock::duration;
typename _Clock::time_point;
_Clock::is_steady;
_Clock::now();
};

Some other implementations, like libstdc++, perform stricter checks. It might be better for MSVC STL to do so. Note that all requirements in the "Return type" column of [tab:time.clock], except for "a class emulating an arithmetic type" (see also #1909), seem statically checkable.

We may also want to perform equivalent checks (for multi-threading components) in old modes, although this requires rewriting in legacy SFINAE, which is still implementable.

template <class _Clock, class = void>
constexpr bool _Is_clock_v = false;
template <class _Clock>
constexpr bool
_Is_clock_v<_Clock, void_t<typename _Clock::rep, typename _Clock::period, typename _Clock::duration,
typename _Clock::time_point, decltype(_Clock::is_steady), decltype(_Clock::now())>> =
true;

Metadata

Metadata

Assignees

No one assigned

    Labels

    chronoC++20 chronoenhancementSomething can be improved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions