名前空間
変種
操作

std::chrono::is_clock

From cppreference.com
< cpp‎ | chrono
 
 
 
ヘッダー <chrono> で定義
template< class T >
struct is_clock;
(C++20以降)

TClock要件を満たす場合、メンバー定数valuetrueとなります。それ以外の場合は、valuefalseとなります。

このトレイトの目的において、実装が型がClock要件を満たせないと判断する範囲は未規定です。ただし、最低限、型Tが以下のすべての条件を満たさない限り、Clockとして適格とはみなされません。

  • 以下の修飾識別子はすべて有効であり、型を示します。
  • T::rep
  • T::period
  • T::duration
  • T::time_point
  • T::is_steady
  • T::now()

プログラムがstd::is_clockまたはstd::is_clock_vの特殊化を追加した場合、その動作は未定義です。

目次

[編集] テンプレートパラメータ

T - チェックする型

[編集] ヘルパー変数テンプレート

template< class T >
constexpr bool is_clock_v = is_clock<T>::value;
(C++20以降)

std::integral_constant から継承

メンバ定数

value
[static]
TClock要件を満たす場合はtrue、それ以外の場合はfalse
(公開静的メンバ定数)

メンバ関数

operator bool
オブジェクトを bool に変換し、value を返します。
(public member function)
operator()
(C++14)
value を返します。
(public member function)

メンバ型

定義
value_type bool
type std::integral_constant<bool, value>

[編集] 実装例

template<class>
struct is_clock : std::false_type {};
 
template<class T>
    requires
        requires
        {
            typename T::rep;
            typename T::period;
            typename T::duration;
            typename T::time_point;
            T::is_steady; // type is not checked
            T::now();     // return type is not checked
        }
struct is_clock<T> : std::true_type {};

[編集] 注記

TがそうでなければClock要件を満たすが、T::is_steadyの型がconst boolではない、またはT::now()の型がT::time_pointではない場合、is_clock_v<T>の結果は未規定となります。

[編集]

#include <chrono>
#include <ratio>
 
static_assert
(
    std::chrono::is_clock_v<std::chrono::utc_clock> and
    not std::chrono::is_clock_v<std::chrono::duration<int, std::exa>>
);
 
int main() {}
English 日本語 中文(简体) 中文(繁體)