Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::chrono::is_clock

      From cppreference.com
      <cpp‎ |chrono
       
       
      Date and time library
      Time point
      (C++11)
      (C++20)
      Duration
      (C++11)
      Clocks
      is_clock
      (C++20)
      (C++20)
      (C++20)
      (C++20)
      (C++20)
      (C++20)
      Time of day
      (C++20)(C++20)
      (C++20)(C++20)
      (C++20)
       
      Defined in header<chrono>
      template<class T>
      struct is_clock;
      (since C++20)

      IfT satisfies theClock requirements, provides the member constantvalue equaltrue. For any other type,value isfalse.

      For the purpose of this trait, the extent to which an implementation determines that a type cannot meet theClock requirements is unspecified, except that a minimumT shall not qualify as aClock unless it meets all following conditions:

      • T::rep
      • T::period
      • T::duration
      • T::time_point
      • T::is_steady
      • T::now()

      If the program adds specializations forstd::is_clock orstd::is_clock_v, the behavior is undefined.

      Contents

      [edit]Template parameters

      T - a type to check

      [edit]Helper variable template

      template<class T>
      constexprbool is_clock_v= is_clock<T>::value;
      (since C++20)
      [edit]

      Inherited fromstd::integral_constant

      Member constants

      value
      [static]
      true ifT satisfies theClock requirements,false otherwise
      (public static member constant)

      Member functions

      operator bool
      converts the object tobool, returnsvalue
      (public member function)
      operator()
      (C++14)
      returnsvalue
      (public member function)

      Member types

      Type Definition
      value_typebool
      typestd::integral_constant<bool, value>

      [edit]Possible implementation

      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{};

      [edit]Notes

      IfT otherwise meets theClock requirements, butT::is_steady is not of typeconstbool, orT::now() is not of typeT::time_point, the result ofis_clock_v<T> is unspecified.

      [edit]Example

      Run this code
      #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(){}
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/is_clock&oldid=176446"

      [8]ページ先頭

      ©2009-2025 Movatter.jp