C++0x chrono - time_point
duration が経過時間を表すのに対して、 time_point は時間軸上のある一点を表します。
namespace std { namespace chrono { template <class Clock, class Duration = typename Clock::duration> class time_point { public: typedef Clock clock; typedef Duration duration; typedef typename duration::rep rep; typedef typename duration::period period; private: duration d_; // 説明のために記述されてるだけ public: time_point(); explicit time_point(const duration& d); // same as time_point() + d template <class Duration2> time_point(const time_point<clock, Duration2>& t); duration time_since_epoch() const; // epoch からの経過時間を返す time_point& operator+=(const duration& d); time_point& operator-=(const duration& d); static constexpr time_point min(); static constexpr time_point max(); }; } }
※ epoch(エポック) というのは、初期時間のことを言うそうです。1970年とか。
time_point は clock と duration を持っていますが、 clock をメンバ変数には保持しません。
これは 2 つの目的で役に立ちます。
1. 異なる clock から始まる time_point が異なる型を持つので、コンパイラは、非互換性の time_point が不適当な方法で使用される場合に失敗するように命じることができます。
2. time_point は now と比較することが多いので、それがどの clock で定義されているか知っていれば、非常に単純になります。