名前空間
変種
操作

標準ライブラリヘッダ <chrono>

提供: cppreference.com
< cpp‎ | header
 
 
 

このヘッダは日付と時間のライブラリの一部です。

目次

[編集] クラス

名前空間 std::chrono で定義
(C++11)
時の間隔
(クラステンプレート) [edit]
システム全体のリアルタイムクロックをベースとする壁時計
(クラス) [edit]
調整されることの決してない単調な時計
(クラス) [edit]
利用可能な最も短い刻み幅を持つ時計
(クラス) [edit]
時のある一点
(クラステンプレート) [edit]
時間が異なる刻み幅を持つ時間に変換可能であることを表します
(クラステンプレート)
ゼロ、最小、最大の刻み数を持つ指定された型の値を構築します
(クラステンプレート)
便利な typedef
名前空間 std::chrono で定義
std::chrono::nanoseconds std::nano の刻み幅を持つ時間型
std::chrono::microseconds std::micro の刻み幅を持つ時間型
std::chrono::milliseconds std::milli の刻み幅を持つ時間型
std::chrono::seconds std::ratio<1> の刻み幅を持つ時間型
std::chrono::minutes std::ratio<60> の刻み幅を持つ時間型
std::chrono::hours std::ratio<3600> の刻み幅を持つ時間型
特殊化
名前空間 std で定義
std::common_type 特性の特殊化
(クラステンプレートの特殊化) [edit]
std::common_type 特性の特殊化
(クラステンプレートの特殊化) [edit]

[編集] 関数

時間
名前空間 std::chrono で定義
引数として時間を取る算術演算を実装します
(関数テンプレート) [edit]
2つの時間を比較します
(関数テンプレート) [edit]
時間を異なる刻み幅を持つ別の時間に変換します
(関数テンプレート) [edit]
時間を別の時間に切り捨て変換します
(関数テンプレート) [edit]
時間を別の時間に切り上げ変換します
(関数テンプレート) [edit]
時間を別の時間の最も近い値に丸めて変換します
(関数テンプレート) [edit]
時間の絶対値を取得します
(関数テンプレート) [edit]
時刻
名前空間 std::chrono で定義
time point に対する加算および減算を行います
(関数テンプレート) [edit]
2つの time point を比較します
(関数テンプレート) [edit]
time point を同じ時計の異なる時間単位の time point に変換します
(関数テンプレート) [edit]
time_point を別の time_point に切り捨て変換します
(関数テンプレート) [edit]
time_point を別の time_point に切り上げ変換します
(関数テンプレート) [edit]
time_point を別の time_point の最も近い値に変換します
(関数テンプレート) [edit]
リテラル
名前空間 std::literals::chrono_literals で定義
時間を表す std::chrono::duration リテラル
(関数) [edit]
分を表す std::chrono::duration リテラル
(関数) [edit]
秒を表す std::chrono::duration リテラル
(関数) [edit]
ミリ秒を表す std::chrono::duration リテラル
(関数) [edit]
マイクロ秒を表す std::chrono::duration リテラル
(関数) [edit]
ナノ秒を表す std::chrono::duration リテラル
(関数) [edit]

[編集] 概要

namespace std {
  namespace chrono {
    // class template duration
    template <class Rep, class Period = ratio<1>> class duration;
    // class template time_point
    template <class Clock, class Duration = typename Clock::duration> class time_point;
  }
  // common_type specializations
  template <class Rep1, class Period1, class Rep2, class Period2>
  struct common_type<chrono::duration<Rep1, Period1>,
                     chrono::duration<Rep2, Period2>>;
  template <class Clock, class Duration1, class Duration2>
  struct common_type<chrono::time_point<Clock, Duration1>,
                     chrono::time_point<Clock, Duration2>>;
  namespace chrono {
    // customization traits
    template <class Rep> struct treat_as_floating_point;
    template <class Rep> struct duration_values;
    template <class Rep>
    constexpr bool treat_as_floating_point_v = treat_as_floating_point<Rep>::value;
    // duration arithmetic
    template <class Rep1, class Period1, class Rep2, class Period2>
    common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
    constexpr operator+(const duration<Rep1, Period1>& lhs,
                        const duration<Rep2, Period2>& rhs);
    template <class Rep1, class Period1, class Rep2, class Period2>
    common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
    constexpr operator-(const duration<Rep1, Period1>& lhs,
                        const duration<Rep2, Period2>& rhs);
    template <class Rep1, class Period, class Rep2>
    duration<common_type_t<Rep1, Rep2>, Period>
    constexpr operator*(const duration<Rep1, Period>& d,
                        const Rep2& s);
    template <class Rep1, class Rep2, class Period>
    duration<common_type_t<Rep1, Rep2>, Period>
    constexpr operator*(const Rep1& s,
                        const duration<Rep2, Period>& d);
    template <class Rep1, class Period, class Rep2>
    duration<common_type_t<Rep1, Rep2>, Period>
    constexpr operator/(const duration<Rep1, Period>& d,
                        const Rep2& s);
    template <class Rep1, class Period1, class Rep2, class Period2>
    common_type_t<Rep1, Rep2>
    constexpr operator/(const duration<Rep1, Period1>& lhs,
                        const duration<Rep2, Period2>& rhs);
    template <class Rep1, class Period, class Rep2>
    duration<common_type_t<Rep1, Rep2>, Period>
    constexpr operator%(const duration<Rep1, Period>& d,
                        const Rep2& s);
    template <class Rep1, class Period1, class Rep2, class Period2>
    common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
    constexpr operator%(const duration<Rep1, Period1>& lhs,
                        const duration<Rep2, Period2>& rhs);
    // duration comparisons
    template <class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator==(const duration<Rep1, Period1>& lhs,
                              const duration<Rep2, Period2>& rhs);
    template <class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator!=(const duration<Rep1, Period1>& lhs,
                              const duration<Rep2, Period2>& rhs);
    template <class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator< (const duration<Rep1, Period1>& lhs,
                              const duration<Rep2, Period2>& rhs);
    template <class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator<=(const duration<Rep1, Period1>& lhs,
                              const duration<Rep2, Period2>& rhs);
    template <class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator> (const duration<Rep1, Period1>& lhs,
                              const duration<Rep2, Period2>& rhs);
    template <class Rep1, class Period1, class Rep2, class Period2>
    constexpr bool operator>=(const duration<Rep1, Period1>& lhs,
                              const duration<Rep2, Period2>& rhs);
    // duration_cast
    template <class ToDuration, class Rep, class Period>
    constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
    template <class ToDuration, class Rep, class Period>
    constexpr ToDuration floor(const duration<Rep, Period>& d);
    template <class ToDuration, class Rep, class Period>
    constexpr ToDuration ceil(const duration<Rep, Period>& d);
    template <class ToDuration, class Rep, class Period>
    constexpr ToDuration round(const duration<Rep, Period>& d);
    // convenience typedefs
    using nanoseconds = duration</*signed integer type of at least 64 bits*/ , nano>;
    using microseconds = duration</*signed integer type of at least 55 bits*/ , micro>;
    using milliseconds = duration</*signed integer type of at least 45 bits*/ , milli>;
    using seconds = duration</*signed integer type of at least 35 bits*/ >;
    using minutes = duration</*signed integer type of at least 29 bits*/ , ratio< 60>>;
    using hours = duration</*signed integer type of at least 23 bits*/ , ratio<3600>>;
    // time_point arithmetic
    template <class Clock, class Duration1, class Rep2, class Period2>
    constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
    operator+(const time_point<Clock, Duration1>& lhs,
              const duration<Rep2, Period2>& rhs);
    template <class Rep1, class Period1, class Clock, class Duration2>
    constexpr time_point<Clock, common_type_t<duration<Rep1, Period1>, Duration2>>
    operator+(const duration<Rep1, Period1>& lhs,
              const time_point<Clock, Duration2>& rhs);
    template <class Clock, class Duration1, class Rep2, class Period2>
    constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
    operator-(const time_point<Clock, Duration1>& lhs,
              const duration<Rep2, Period2>& rhs);
    template <class Clock, class Duration1, class Duration2>
    constexpr common_type_t<Duration1, Duration2>
    operator-(const time_point<Clock, Duration1>& lhs,
              const time_point<Clock, Duration2>& rhs);
    // time_point comparisons
    template <class Clock, class Duration1, class Duration2>
    constexpr bool operator==(const time_point<Clock, Duration1>& lhs,
                              const time_point<Clock, Duration2>& rhs);
    template <class Clock, class Duration1, class Duration2>
    constexpr bool operator!=(const time_point<Clock, Duration1>& lhs,
                              const time_point<Clock, Duration2>& rhs);
    template <class Clock, class Duration1, class Duration2>
    constexpr bool operator< (const time_point<Clock, Duration1>& lhs,
                              const time_point<Clock, Duration2>& rhs);
    template <class Clock, class Duration1, class Duration2>
    constexpr bool operator<=(const time_point<Clock, Duration1>& lhs,
                              const time_point<Clock, Duration2>& rhs);
    template <class Clock, class Duration1, class Duration2>
    constexpr bool operator> (const time_point<Clock, Duration1>& lhs,
                              const time_point<Clock, Duration2>& rhs);
    template <class Clock, class Duration1, class Duration2>
    constexpr bool operator>=(const time_point<Clock, Duration1>& lhs,
                              const time_point<Clock, Duration2>& rhs);
    // time_point_cast
    template <class ToDuration, class Clock, class Duration>
    constexpr time_point<Clock, ToDuration>
    time_point_cast(const time_point<Clock, Duration>& t);
    template <class ToDuration, class Clock, class Duration>
    constexpr time_point<Clock, ToDuration>
    floor(const time_point<Clock, Duration>& tp);
    template <class ToDuration, class Clock, class Duration>
    constexpr time_point<Clock, ToDuration>
    ceil(const time_point<Clock, Duration>& tp);
    template <class ToDuration, class Clock, class Duration>
    constexpr time_point<Clock, ToDuration>
    round(const time_point<Clock, Duration>& tp);
    // specialized algorithms
    template <class Rep, class Period>
    constexpr duration<Rep, Period> abs(duration<Rep, Period> d);
    // clocks
    class system_clock;
    class steady_clock;
    class high_resolution_clock;
  }
  inline namespace literals {
    inline namespace chrono_literals {
      // suffixes for duration literals
      constexpr chrono::hours operator "" h(unsigned long long);
      constexpr chrono::duration</*unspecified*/,
                                 ratio<3600,1>> operator "" h(long double);
      constexpr chrono::minutes operator "" min(unsigned long long);
      constexpr chrono::duration</*unspecified*/,
                                 ratio<60,1>> operator "" min(long double);
      constexpr chrono::seconds operator "" s(unsigned long long);
      constexpr chrono::duration</*unspecified*/ > operator "" s(long double);
      constexpr chrono::milliseconds operator "" ms(unsigned long long);
      constexpr chrono::duration</*unspecified*/,
                                 milli> operator "" ms(long double);
      constexpr chrono::microseconds operator "" us(unsigned long long);
      constexpr chrono::duration</*unspecified*/,
                                 micro> operator "" us(long double);
      constexpr chrono::nanoseconds operator "" ns(unsigned long long);
      constexpr chrono::duration</*unspecified*/, 
                                 nano> operator "" ns(long double);
    }
  }
  namespace chrono {
    using namespace literals::chrono_literals;
  }

[編集] std::chrono::treat_as_floating_point

template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> { };

[編集] std::chrono::duration_values

template <class Rep>
struct duration_values {
public:
  static constexpr Rep zero();
  static constexpr Rep min();
  static constexpr Rep max();
};

[編集] std::chrono::duration

template <class Rep, class Period = ratio<1>>
class duration {
public:
  using rep = Rep;
  using period = Period;
private:
  rep rep_; // exposition only
public:
  // construct/copy/destroy
  constexpr duration() = default;
  template <class Rep2>
  constexpr explicit duration(const Rep2& r);
  template <class Rep2, class Period2>
  constexpr duration(const duration<Rep2, Period2>& d);
  ~duration() = default;
  duration(const duration&) = default;
  duration& operator=(const duration&) = default;
  // observer
  constexpr rep count() const;
  // arithmetic
  constexpr duration operator+() const;
  constexpr duration operator-() const;
  constexpr duration& operator++();
  constexpr duration operator++(int);
  constexpr duration& operator--();
  constexpr duration operator--(int);
  constexpr duration& operator+=(const duration& d);
  constexpr duration& operator-=(const duration& d);
  constexpr duration& operator*=(const rep& rhs);
  constexpr duration& operator/=(const rep& rhs);
  constexpr duration& operator%=(const rep& rhs);
  constexpr duration& operator%=(const duration& rhs);
  // special values
  static constexpr duration zero();
  static constexpr duration min();
  static constexpr duration max();
};

[編集] std::chrono::time_point

template <class Clock, class Duration = typename Clock::duration>
class time_point {
public:
  using clock = Clock;
  using duration = Duration;
  using rep = typename duration::rep;
  using period = typename duration::period;
private:
  duration d_; // exposition only
public:
  // construct
  constexpr time_point(); // has value epoch
  constexpr explicit time_point(const duration& d); // same as time_point() + d
  template <class Duration2>
  constexpr time_point(const time_point<clock, Duration2>& t);
  // observer
  constexpr duration time_since_epoch() const;
  // arithmetic
  constexpr time_point& operator+=(const duration& d);
  constexpr time_point& operator-=(const duration& d);
  // special values
  static constexpr time_point min();
  static constexpr time_point max();
};

[編集] std::chrono::system_clock

class system_clock {
public:
  using rep = /*see description*/ ;
  using period = ratio</*unspecified*/, /*unspecified*/ >;
  using duration = chrono::duration<rep, period>;
  using time_point = chrono::time_point<system_clock>;
  static constexpr bool is_steady = /*unspecified*/ ;
  static time_point now() noexcept;
  // Map to C API
  static time_t to_time_t (const time_point& t) noexcept;
  static time_point from_time_t(time_t t) noexcept;
};

[編集] std::chrono::steady_clock

class steady_clock {
public:
  using rep = /*unspecified*/ ;
  using period = ratio</*unspecified*/, /*unspecified*/ >;
  using duration = chrono::duration<rep, period>;
  using time_point = chrono::time_point</*unspecified*/, duration>;
  static constexpr bool is_steady = true;
  static time_point now() noexcept;
};

[編集] std::chrono::high_resolution_clock

class high_resolution_clock {
public:
  using rep = /*unspecified*/ ;
  using period = ratio</*unspecified*/, /*unspecified*/ >;
  using duration = chrono::duration<rep, period>;
  using time_point = chrono::time_point</*unspecified*/, duration>;
  static constexpr bool is_steady = /*unspecified*/ ;
  static time_point now() noexcept;
};