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 // reference operator[](size_type __i); 12 // const_reference operator[](size_type __i) const; 13 // 14 // reference at(size_type __i); 15 // const_reference at(size_type __i) const; 16 // 17 // reference front(); 18 // const_reference front() const; 19 // 20 // reference back(); 21 // const_reference back() const; 22 // libc++ marks these as 'noexcept' 23 24 #include <deque> 25 #include <cassert> 26 27 #include "min_allocator.h" 28 #include "test_macros.h" 29 30 template <class C> 31 C 32 make(int size, int start = 0 ) 33 { 34 const int b = 4096 / sizeof(int); 35 int init = 0; 36 if (start > 0) 37 { 38 init = (start+1) / b + ((start+1) % b != 0); 39 init *= b; 40 --init; 41 } 42 C c(init, 0); 43 for (int i = 0; i < init-start; ++i) 44 c.pop_back(); 45 for (int i = 0; i < size; ++i) 46 c.push_back(i); 47 for (int i = 0; i < start; ++i) 48 c.pop_front(); 49 return c; 50 } 51 52 int main(int, char**) 53 { 54 { 55 typedef std::deque<int> C; 56 C c = make<std::deque<int> >(10); 57 LIBCPP_ASSERT_NOEXCEPT(c[0]); 58 ASSERT_SAME_TYPE(C::reference, decltype(c[0])); 59 for (int i = 0; i < 10; ++i) 60 assert(c[i] == i); 61 for (int i = 0; i < 10; ++i) 62 assert(c.at(i) == i); 63 assert(c.front() == 0); 64 assert(c.back() == 9); 65 } 66 { 67 typedef std::deque<int> C; 68 const C c = make<std::deque<int> >(10); 69 LIBCPP_ASSERT_NOEXCEPT(c[0]); 70 ASSERT_SAME_TYPE(C::const_reference, decltype(c[0])); 71 for (int i = 0; i < 10; ++i) 72 assert(c[i] == i); 73 for (int i = 0; i < 10; ++i) 74 assert(c.at(i) == i); 75 assert(c.front() == 0); 76 assert(c.back() == 9); 77 } 78 #if TEST_STD_VER >= 11 79 { 80 typedef std::deque<int, min_allocator<int>> C; 81 C c = make<std::deque<int, min_allocator<int>> >(10); 82 LIBCPP_ASSERT_NOEXCEPT(c[0]); 83 ASSERT_SAME_TYPE(C::reference, decltype(c[0])); 84 for (int i = 0; i < 10; ++i) 85 assert(c[i] == i); 86 for (int i = 0; i < 10; ++i) 87 assert(c.at(i) == i); 88 assert(c.front() == 0); 89 assert(c.back() == 9); 90 } 91 { 92 typedef std::deque<int, min_allocator<int>> C; 93 const C c = make<std::deque<int, min_allocator<int>> >(10); 94 LIBCPP_ASSERT_NOEXCEPT(c[0]); 95 ASSERT_SAME_TYPE(C::const_reference, decltype(c[0])); 96 for (int i = 0; i < 10; ++i) 97 assert(c[i] == i); 98 for (int i = 0; i < 10; ++i) 99 assert(c.at(i) == i); 100 assert(c.front() == 0); 101 assert(c.back() == 9); 102 } 103 #endif 104 105 return 0; 106 } 107