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