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 // UNSUPPORTED: c++98, c++03 10 11 // <deque> 12 13 // deque(deque&&); 14 15 #include <deque> 16 #include <cassert> 17 18 #include "MoveOnly.h" 19 #include "test_allocator.h" 20 #include "min_allocator.h" 21 22 int main(int, char**) 23 { 24 { 25 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; 26 int* an = ab + sizeof(ab)/sizeof(ab[0]); 27 typedef test_allocator<MoveOnly> A; 28 std::deque<MoveOnly, A> c1(A(1)); 29 for (int* p = ab; p < an; ++p) 30 c1.push_back(MoveOnly(*p)); 31 std::deque<MoveOnly, A> c2(A(2)); 32 for (int* p = ab; p < an; ++p) 33 c2.push_back(MoveOnly(*p)); 34 A old_a = c1.get_allocator(); 35 std::deque<MoveOnly, A> c3 = std::move(c1); 36 assert(c2 == c3); 37 assert(c1.size() == 0); 38 assert(c3.get_allocator() == old_a); 39 assert(c1.get_allocator() == A(test_alloc_base::moved_value)); 40 } 41 { 42 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; 43 int* an = ab + sizeof(ab)/sizeof(ab[0]); 44 typedef other_allocator<MoveOnly> A; 45 std::deque<MoveOnly, A> c1(A(1)); 46 for (int* p = ab; p < an; ++p) 47 c1.push_back(MoveOnly(*p)); 48 std::deque<MoveOnly, A> c2(A(2)); 49 for (int* p = ab; p < an; ++p) 50 c2.push_back(MoveOnly(*p)); 51 std::deque<MoveOnly, A> c3 = std::move(c1); 52 assert(c2 == c3); 53 assert(c1.size() == 0); 54 assert(c3.get_allocator() == c1.get_allocator()); 55 } 56 { 57 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; 58 int* an = ab + sizeof(ab)/sizeof(ab[0]); 59 typedef min_allocator<MoveOnly> A; 60 std::deque<MoveOnly, A> c1(A{}); 61 for (int* p = ab; p < an; ++p) 62 c1.push_back(MoveOnly(*p)); 63 std::deque<MoveOnly, A> c2(A{}); 64 for (int* p = ab; p < an; ++p) 65 c2.push_back(MoveOnly(*p)); 66 std::deque<MoveOnly, A> c3 = std::move(c1); 67 assert(c2 == c3); 68 assert(c1.size() == 0); 69 assert(c3.get_allocator() == c1.get_allocator()); 70 } 71 72 return 0; 73 } 74