Szerkesztés

Megosztás a következőn keresztül:


is_clock structure

A type trait that determines whether the specified type meets the requirements to be a clock.

Syntax

template<class T> struct is_clock; // C++20

Helper variable template

 template<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20

Parameters

T
The type to test.

Members

Name Description
value Indicates whether T satisfies the requirements to be a clock.
operator () Returns value.
operator bool Returns value.

Remarks

A clock has a rep, period, duration, time_point, is_steady, and a now() function.

For more details about the requirements to be a C++17 clock, see Cpp17Clock requirements.

The following code works because is_clock, derives from Cpp17UnaryTypeTrait, which derives from integral_constant. This is where value_type, which is a bool, and type, which is a std::integral_constant<bool, value> come from.

Example

#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    is_clock<system_clock> ic;

    std::cout << std::boolalpha << ic.value << ", " << ic() << ", " << (bool)ic;
}
true, true, true

Requirements

Header: <chrono>

Namespace: std::chrono

Compiler Option: /std:c++latest

Value

Get whether the specified type satisfies the requirements to be a clock.

static constexpr T value;

Return value

true if specified type meets the requirements to be a clock. Otherwise, false.

operator()

constexpr value_type operator()() const noexcept

Returns value, that is, whether the specified type meets the requirements to be a clock.

Return value

true if specified type meets the requirements to be a clock. Otherwise, false.

operator bool

constexpr operator value_type() const noexcept

Returns value, that is, whether the specified type meets the requirements to be a clock.

Return value

true if specified type meets the requirements to be a clock. Otherwise, false.

See also

<chrono>
Header Files Reference