15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
9*31cbe0f2SLouis Dionne // UNSUPPORTED: c++03
10a9d646a0SEric Fiselier 
115a83710eSEric Fiselier // <deque>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // deque(deque&& c, const allocator_type& a);
145a83710eSEric Fiselier 
155a83710eSEric Fiselier #include <deque>
165a83710eSEric Fiselier #include <cassert>
175a83710eSEric Fiselier 
18c02236b6SMarshall Clow #include "test_macros.h"
19949389c3SMarshall Clow #include "MoveOnly.h"
205a83710eSEric Fiselier #include "test_allocator.h"
215a83710eSEric Fiselier #include "min_allocator.h"
225a83710eSEric Fiselier 
main(int,char **)232df59c50SJF Bastien int main(int, char**)
245a83710eSEric Fiselier {
255a83710eSEric Fiselier     {
265a83710eSEric Fiselier         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
27c02236b6SMarshall Clow         const int* an = ab + sizeof(ab)/sizeof(ab[0]);
285a83710eSEric Fiselier         typedef test_allocator<MoveOnly> A;
295a83710eSEric Fiselier         std::deque<MoveOnly, A> c1(A(1));
305a83710eSEric Fiselier         for (int* p = ab; p < an; ++p)
315a83710eSEric Fiselier             c1.push_back(MoveOnly(*p));
325a83710eSEric Fiselier         std::deque<MoveOnly, A> c2(A(1));
335a83710eSEric Fiselier         for (int* p = ab; p < an; ++p)
345a83710eSEric Fiselier             c2.push_back(MoveOnly(*p));
35c02236b6SMarshall Clow         std::deque<MoveOnly, A> c3(std::move(c1), A(3)); // unequal allocator
365a83710eSEric Fiselier         assert(c2 == c3);
375a83710eSEric Fiselier         assert(c3.get_allocator() == A(3));
38c02236b6SMarshall Clow         LIBCPP_ASSERT(c1.size() != 0);
395a83710eSEric Fiselier     }
405a83710eSEric Fiselier     {
415a83710eSEric Fiselier         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
42c02236b6SMarshall Clow         const int* an = ab + sizeof(ab)/sizeof(ab[0]);
435a83710eSEric Fiselier         typedef test_allocator<MoveOnly> A;
445a83710eSEric Fiselier         std::deque<MoveOnly, A> c1(A(1));
455a83710eSEric Fiselier         for (int* p = ab; p < an; ++p)
465a83710eSEric Fiselier             c1.push_back(MoveOnly(*p));
475a83710eSEric Fiselier         std::deque<MoveOnly, A> c2(A(1));
485a83710eSEric Fiselier         for (int* p = ab; p < an; ++p)
495a83710eSEric Fiselier             c2.push_back(MoveOnly(*p));
50c02236b6SMarshall Clow         std::deque<MoveOnly, A> c3(std::move(c1), A(1)); // equal allocator
515a83710eSEric Fiselier         assert(c2 == c3);
525a83710eSEric Fiselier         assert(c3.get_allocator() == A(1));
53c02236b6SMarshall Clow         LIBCPP_ASSERT(c1.size() == 0);
545a83710eSEric Fiselier     }
555a83710eSEric Fiselier     {
565a83710eSEric Fiselier         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
57c02236b6SMarshall Clow         const int* an = ab + sizeof(ab)/sizeof(ab[0]);
585a83710eSEric Fiselier         typedef other_allocator<MoveOnly> A;
595a83710eSEric Fiselier         std::deque<MoveOnly, A> c1(A(1));
605a83710eSEric Fiselier         for (int* p = ab; p < an; ++p)
615a83710eSEric Fiselier             c1.push_back(MoveOnly(*p));
625a83710eSEric Fiselier         std::deque<MoveOnly, A> c2(A(1));
635a83710eSEric Fiselier         for (int* p = ab; p < an; ++p)
645a83710eSEric Fiselier             c2.push_back(MoveOnly(*p));
65c02236b6SMarshall Clow         std::deque<MoveOnly, A> c3(std::move(c1), A(3)); // unequal allocator
665a83710eSEric Fiselier         assert(c2 == c3);
675a83710eSEric Fiselier         assert(c3.get_allocator() == A(3));
68c02236b6SMarshall Clow         LIBCPP_ASSERT(c1.size() != 0);
695a83710eSEric Fiselier     }
705a83710eSEric Fiselier     {
715a83710eSEric Fiselier         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
72c02236b6SMarshall Clow         const int* an = ab + sizeof(ab)/sizeof(ab[0]);
735a83710eSEric Fiselier         typedef min_allocator<MoveOnly> A;
745a83710eSEric Fiselier         std::deque<MoveOnly, A> c1(A{});
755a83710eSEric Fiselier         for (int* p = ab; p < an; ++p)
765a83710eSEric Fiselier             c1.push_back(MoveOnly(*p));
775a83710eSEric Fiselier         std::deque<MoveOnly, A> c2(A{});
785a83710eSEric Fiselier         for (int* p = ab; p < an; ++p)
795a83710eSEric Fiselier             c2.push_back(MoveOnly(*p));
80c02236b6SMarshall Clow         std::deque<MoveOnly, A> c3(std::move(c1), A());  // equal allocator
815a83710eSEric Fiselier         assert(c2 == c3);
825a83710eSEric Fiselier         assert(c3.get_allocator() == A());
83c02236b6SMarshall Clow         LIBCPP_ASSERT(c1.size() == 0);
845a83710eSEric Fiselier     }
852df59c50SJF Bastien 
862df59c50SJF Bastien   return 0;
875a83710eSEric Fiselier }
88