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 | |
9 | // <deque> |
10 | |
11 | // Test nested types and default template args: |
12 | |
13 | // template <class T, class Allocator = allocator<T> > |
14 | // class deque; |
15 | |
16 | // iterator, const_iterator |
17 | |
18 | #include <deque> |
19 | #include <iterator> |
20 | #include <cassert> |
21 | |
22 | #include "test_macros.h" |
23 | #include "min_allocator.h" |
24 | |
25 | int main(int, char**) { |
26 | { |
27 | typedef std::deque<int> C; |
28 | C c; |
29 | C::iterator i; |
30 | i = c.begin(); |
31 | C::const_iterator j; |
32 | j = c.cbegin(); |
33 | assert(i == j); |
34 | } |
35 | #if TEST_STD_VER >= 11 |
36 | { |
37 | typedef std::deque<int, min_allocator<int>> C; |
38 | C c; |
39 | C::iterator i; |
40 | i = c.begin(); |
41 | C::const_iterator j; |
42 | j = c.cbegin(); |
43 | |
44 | assert(i == j); |
45 | assert(!(i != j)); |
46 | |
47 | assert(!(i < j)); |
48 | assert((i <= j)); |
49 | |
50 | assert(!(i > j)); |
51 | assert((i >= j)); |
52 | |
53 | # if TEST_STD_VER >= 20 |
54 | // P1614 + LWG3352 |
55 | // When the allocator does not have operator<=> then the iterator uses a |
56 | // fallback to provide operator<=>. |
57 | // Make sure to test with an allocator that does not have operator<=>. |
58 | static_assert(!std::three_way_comparable<min_allocator<int>, std::strong_ordering>); |
59 | static_assert(std::three_way_comparable<typename C::iterator, std::strong_ordering>); |
60 | |
61 | std::same_as<std::strong_ordering> decltype(auto) r1 = i <=> j; |
62 | assert(r1 == std::strong_ordering::equal); |
63 | # endif |
64 | } |
65 | #endif |
66 | #if TEST_STD_VER > 11 |
67 | { // N3644 testing |
68 | std::deque<int>::iterator ii1{}, ii2{}; |
69 | std::deque<int>::iterator ii4 = ii1; |
70 | std::deque<int>::const_iterator cii{}; |
71 | assert(ii1 == ii2); |
72 | assert(ii1 == ii4); |
73 | |
74 | assert(!(ii1 != ii2)); |
75 | |
76 | assert((ii1 == cii)); |
77 | assert((cii == ii1)); |
78 | assert(!(ii1 != cii)); |
79 | assert(!(cii != ii1)); |
80 | assert(!(ii1 < cii)); |
81 | assert(!(cii < ii1)); |
82 | assert((ii1 <= cii)); |
83 | assert((cii <= ii1)); |
84 | assert(!(ii1 > cii)); |
85 | assert(!(cii > ii1)); |
86 | assert((ii1 >= cii)); |
87 | assert((cii >= ii1)); |
88 | assert(cii - ii1 == 0); |
89 | assert(ii1 - cii == 0); |
90 | |
91 | // std::deque<int> c; |
92 | // assert ( ii1 != c.cbegin()); |
93 | // assert ( cii != c.begin()); |
94 | // assert ( cii != c.cend()); |
95 | // assert ( ii1 != c.end()); |
96 | |
97 | # if TEST_STD_VER >= 20 |
98 | // P1614 + LWG3352 |
99 | std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2; |
100 | assert(r1 == std::strong_ordering::equal); |
101 | |
102 | std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2; |
103 | assert(r2 == std::strong_ordering::equal); |
104 | # endif // TEST_STD_VER > 20 |
105 | } |
106 | #endif |
107 | |
108 | return 0; |
109 | } |
110 | |