File tree Expand file tree Collapse file tree 6 files changed +176
-0
lines changed
test/std/time/time.point/time.point.arithmetic Expand file tree Collapse file tree 6 files changed +176
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,19 @@ class time_point {
5858
5959 // arithmetic
6060
61+ #if _LIBCPP_STD_VER >= 20
62+ _LIBCPP_HIDE_FROM_ABI constexpr time_point& operator ++() {
63+ ++__d_;
64+ return *this ;
65+ }
66+ _LIBCPP_HIDE_FROM_ABI constexpr time_point operator ++(int ) { return time_point (__d_++); }
67+ _LIBCPP_HIDE_FROM_ABI constexpr time_point& operator --() {
68+ --__d_;
69+ return *this ;
70+ }
71+ _LIBCPP_HIDE_FROM_ABI constexpr time_point operator --(int ) { return time_point (__d_--); }
72+ #endif // _LIBCPP_STD_VER >= 20
73+
6174 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 time_point& operator +=(const duration& __d) {
6275 __d_ += __d;
6376 return *this ;
Original file line number Diff line number Diff line change @@ -132,6 +132,11 @@ public:
132132
133133 // arithmetic
134134
135+ constexpr time_point& operator++(); // C++20
136+ constexpr time_point operator++(int); // C++20
137+ constexpr time_point& operator--(); // C++20
138+ constexpr time_point operator--(int); // C++20
139+
135140 time_point& operator+=(const duration& d); // constexpr in C++17
136141 time_point& operator-=(const duration& d); // constexpr in C++17
137142
Original file line number Diff line number Diff line change 1+ // ===----------------------------------------------------------------------===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+ // UNSUPPORTED: c++03, c++11, c++14, c++17
9+
10+ // <chrono>
11+
12+ // time_point
13+
14+ // constexpr time_point& operator++();
15+
16+ #include < chrono>
17+ #include < cassert>
18+
19+ #include " test_macros.h"
20+
21+ constexpr bool constexpr_test () {
22+ typedef std::chrono::system_clock Clock;
23+ typedef std::chrono::milliseconds Duration;
24+ std::chrono::time_point<Clock, Duration> t (Duration (5 ));
25+ return (++t).time_since_epoch () == Duration (6 );
26+ }
27+
28+ int main (int , char **) {
29+ typedef std::chrono::system_clock Clock;
30+ typedef std::chrono::milliseconds Duration;
31+ std::chrono::time_point<Clock, Duration> t (Duration (3 ));
32+ std::chrono::time_point<Clock, Duration>& tref = ++t;
33+ assert (&tref == &t);
34+ assert (t.time_since_epoch () == Duration (4 ));
35+
36+ static_assert (constexpr_test ());
37+
38+ return 0 ;
39+ }
Original file line number Diff line number Diff line change 1+ // ===----------------------------------------------------------------------===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+ // UNSUPPORTED: c++03, c++11, c++14, c++17
9+
10+ // <chrono>
11+
12+ // time_point
13+
14+ // constexpr time_point operator++(int);
15+
16+ #include < chrono>
17+ #include < cassert>
18+
19+ #include " test_macros.h"
20+
21+ constexpr bool test_constexpr () {
22+ typedef std::chrono::system_clock Clock;
23+ typedef std::chrono::milliseconds Duration;
24+ std::chrono::time_point<Clock, Duration> t1 (Duration (3 ));
25+ std::chrono::time_point<Clock, Duration> t2 = t1++;
26+ return t1.time_since_epoch () == Duration (4 ) && t2.time_since_epoch () == Duration (3 );
27+ }
28+
29+ int main (int , char **) {
30+ typedef std::chrono::system_clock Clock;
31+ typedef std::chrono::milliseconds Duration;
32+ std::chrono::time_point<Clock, Duration> t1 (Duration (3 ));
33+ std::chrono::time_point<Clock, Duration> t2 = t1++;
34+ assert (t1.time_since_epoch () == Duration (4 ));
35+ assert (t2.time_since_epoch () == Duration (3 ));
36+
37+ static_assert (test_constexpr ());
38+
39+ return 0 ;
40+ }
Original file line number Diff line number Diff line change 1+ // ===----------------------------------------------------------------------===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+ // UNSUPPORTED: c++03, c++11, c++14, c++17
9+
10+ // <chrono>
11+
12+ // time_point
13+
14+ // constexpr time_point& operator--();
15+
16+ #include < chrono>
17+ #include < cassert>
18+
19+ #include " test_macros.h"
20+
21+ constexpr bool constexpr_test () {
22+ typedef std::chrono::system_clock Clock;
23+ typedef std::chrono::milliseconds Duration;
24+ std::chrono::time_point<Clock, Duration> t (Duration (5 ));
25+ return (--t).time_since_epoch () == Duration (4 );
26+ }
27+
28+ int main (int , char **) {
29+ typedef std::chrono::system_clock Clock;
30+ typedef std::chrono::milliseconds Duration;
31+ std::chrono::time_point<Clock, Duration> t (Duration (3 ));
32+ std::chrono::time_point<Clock, Duration>& tref = --t;
33+ assert (&tref == &t);
34+ assert (t.time_since_epoch () == Duration (2 ));
35+
36+ static_assert (constexpr_test ());
37+
38+ return 0 ;
39+ }
Original file line number Diff line number Diff line change 1+ // ===----------------------------------------------------------------------===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+ // UNSUPPORTED: c++03, c++11, c++14, c++17
9+
10+ // <chrono>
11+
12+ // time_point
13+
14+ // constexpr time_point operator--(int);
15+
16+ #include < chrono>
17+ #include < cassert>
18+
19+ #include " test_macros.h"
20+
21+ constexpr bool test_constexpr () {
22+ typedef std::chrono::system_clock Clock;
23+ typedef std::chrono::milliseconds Duration;
24+ std::chrono::time_point<Clock, Duration> t1 (Duration (3 ));
25+ std::chrono::time_point<Clock, Duration> t2 = t1--;
26+ return t1.time_since_epoch () == Duration (2 ) && t2.time_since_epoch () == Duration (3 );
27+ }
28+
29+ int main (int , char **) {
30+ typedef std::chrono::system_clock Clock;
31+ typedef std::chrono::milliseconds Duration;
32+ std::chrono::time_point<Clock, Duration> t1 (Duration (3 ));
33+ std::chrono::time_point<Clock, Duration> t2 = t1--;
34+ assert (t1.time_since_epoch () == Duration (2 ));
35+ assert (t2.time_since_epoch () == Duration (3 ));
36+
37+ static_assert (test_constexpr ());
38+
39+ return 0 ;
40+ }
You can’t perform that action at this time.
0 commit comments