Home | History | Annotate | Download | only in deque.cons
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <deque>
     11 
     12 // deque& operator=(deque&& c);
     13 
     14 #include <deque>
     15 #include <cassert>
     16 
     17 #include "../../../MoveOnly.h"
     18 #include "test_allocator.h"
     19 #include "min_allocator.h"
     20 
     21 int main()
     22 {
     23 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     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(5));
     29         for (int* p = ab; p < an; ++p)
     30             c1.push_back(MoveOnly(*p));
     31         std::deque<MoveOnly, A> c2(A(5));
     32         for (int* p = ab; p < an; ++p)
     33             c2.push_back(MoveOnly(*p));
     34         std::deque<MoveOnly, A> c3(A(5));
     35         c3 = std::move(c1);
     36         assert(c2 == c3);
     37         assert(c1.size() == 0);
     38         assert(c3.get_allocator() == A(5));
     39     }
     40     {
     41         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
     42         int* an = ab + sizeof(ab)/sizeof(ab[0]);
     43         typedef test_allocator<MoveOnly> A;
     44         std::deque<MoveOnly, A> c1(A(5));
     45         for (int* p = ab; p < an; ++p)
     46             c1.push_back(MoveOnly(*p));
     47         std::deque<MoveOnly, A> c2(A(5));
     48         for (int* p = ab; p < an; ++p)
     49             c2.push_back(MoveOnly(*p));
     50         std::deque<MoveOnly, A> c3(A(6));
     51         c3 = std::move(c1);
     52         assert(c2 == c3);
     53         assert(c1.size() != 0);
     54         assert(c3.get_allocator() == A(6));
     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 other_allocator<MoveOnly> A;
     60         std::deque<MoveOnly, A> c1(A(5));
     61         for (int* p = ab; p < an; ++p)
     62             c1.push_back(MoveOnly(*p));
     63         std::deque<MoveOnly, A> c2(A(5));
     64         for (int* p = ab; p < an; ++p)
     65             c2.push_back(MoveOnly(*p));
     66         std::deque<MoveOnly, A> c3(A(6));
     67         c3 = std::move(c1);
     68         assert(c2 == c3);
     69         assert(c1.size() == 0);
     70         assert(c3.get_allocator() == A(5));
     71     }
     72 #if __cplusplus >= 201103L
     73     {
     74         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
     75         int* an = ab + sizeof(ab)/sizeof(ab[0]);
     76         typedef min_allocator<MoveOnly> A;
     77         std::deque<MoveOnly, A> c1(A{});
     78         for (int* p = ab; p < an; ++p)
     79             c1.push_back(MoveOnly(*p));
     80         std::deque<MoveOnly, A> c2(A{});
     81         for (int* p = ab; p < an; ++p)
     82             c2.push_back(MoveOnly(*p));
     83         std::deque<MoveOnly, A> c3(A{});
     84         c3 = std::move(c1);
     85         assert(c2 == c3);
     86         assert(c1.size() == 0);
     87         assert(c3.get_allocator() == A());
     88     }
     89 #endif
     90 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     91 }
     92