function template
<chrono>

std::chrono::time_point operators

member functions
time_point& operator+= (const duration& dtn);time_point& operator-= (const duration& dtn);
non-member functions
template <class Clock, class Duration1, class Rep2, class Period2>  time_point<Clock,typename common_type<Duration1,duration<Rep2,Period2>>::type>  operator+ (const time_point<Clock,Duration1>& lhs, const duration<Rep2,Period2>& dtn);template <class Rep1, Period1, class Clock, class Duration2>  time_point<Clock,typename common_type<duration<Rep1,Period1>,Duration2>::type>  operator+ (const duration<Rep1,Period1>& dtn, const time_point<Clock,Duration2>& rhs);template <class Clock, class Duration1, class Rep2, class Period2>  time_point<Clock,typename common_type<Duration1,duration<Rep2,Period2>>::type>  operator- (const time_point<Clock,Duration1>& lhs, const duration<Rep2,Period2>& dtn);template <class Clock, class Duration1, class Duration2>  typename common_type<Duration1,Duration2>::type  operator- (const time_point<Clock,Duration1>& lhs, const time_point<Clock,Duration2>& rhs);template <class Clock, class Duration1, class Duration2>  bool operator== (const time_point<Clock,Duration1>& lhs, const time_point<Clock,Duration2>& rhs);template <class Clock, class Duration1, class Duration2>  bool operator!= (const time_point<Clock,Duration1>& lhs, const time_point<Clock,Duration2>& rhs);template <class Clock, class Duration1, class Duration2>  bool operator<  (const time_point<Clock,Duration1>& lhs, const time_point<Clock,Duration2>& rhs);template <class Clock, class Duration1, class Duration2>  bool operator>  (const time_point<Clock,Duration1>& lhs, const time_point<Clock,Duration2>& rhs);template <class Clock, class Duration1, class Duration2>  bool operator>= (const time_point<Clock,Duration1>& lhs, const time_point<Clock,Duration2>& rhs);template <class Clock, class Duration1, class Duration2>  bool operator<= (const time_point<Clock,Duration1>& lhs, const time_point<Clock,Duration2>& rhs);
Operators for time_point
Performs the appropriate operation on the time_point objects involved as if it was applied directly on its internal duration object. The following operations are supported:

operationreturns
compound assignment
(member functions)
tp += dtn*this
tp -= dtn*this
arithmetic operators
(non-member functions)
tp + dtna time_point value
dtn + tpa time_point value
tp - dtna time_point value
tp - tp2a duration value
relational operators
(non-member functions)
tp == tp2a bool value
tp != tp2a bool value
tp < tp2a bool value
tp > tp2a bool value
tp >= tp2a bool value
tp <= tp2a bool value
Where tp and tp2 are time_point objects, and dtn is a duration object.

Parameters

dtn
A duration object.
duration is a member type, defined as the duration type used by the object.
lhs,rhs
time_point objects (to the left- and right-hand side of the operator, respectively).

Return value

The result of the operation.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// time_point operators
#include <iostream>
#include <chrono>

int main ()
{

  using namespace std::chrono;

  system_clock::time_point tp,tp2;                // epoch value
  system_clock::duration dtn (duration<int>(1));  // 1 second

                      //  tp     tp2    dtn
                      //  ---    ---    ---
  tp += dtn;          //  e+1s   e      1s
  tp2 -= dtn;         //  e+1s   e-1s   1s
  tp2 = tp + dtn;     //  e+1s   e+2s   1s
  tp = dtn + tp2;     //  e+3s   e+2s   1s
  tp2 = tp2 - dtn;    //  e+3s   e+1s   1s
  dtn = tp - tp2;     //  e+3s   e+1s   2s

  std::cout << std::boolalpha;
  std::cout << "tp == tp2: " << (tp==tp2) << std::endl;
  std::cout << "tp > tp2: " << (tp>tp2) << std::endl;
  std::cout << "dtn: " << dtn.count() << std::endl;

  return 0;
}

Possible output:
tp == tp2: false
tp > tp2: true
dtn: 2000000


See also