Home | History | Annotate | Download | only in list.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 // <list>
     11 
     12 // list(list&& c, const allocator_type& a);
     13 
     14 #include <list>
     15 #include <cassert>
     16 #include "../../../MoveOnly.h"
     17 #include "test_allocator.h"
     18 #include "min_allocator.h"
     19 
     20 int main()
     21 {
     22 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     23     {
     24         std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
     25         std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
     26         for (int i = 1; i <= 3; ++i)
     27         {
     28             l.push_back(i);
     29             lo.push_back(i);
     30         }
     31         std::list<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(6));
     32         assert(l2 == lo);
     33         assert(!l.empty());
     34         assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
     35     }
     36     {
     37         std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
     38         std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
     39         for (int i = 1; i <= 3; ++i)
     40         {
     41             l.push_back(i);
     42             lo.push_back(i);
     43         }
     44         std::list<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(5));
     45         assert(l2 == lo);
     46         assert(l.empty());
     47         assert(l2.get_allocator() == test_allocator<MoveOnly>(5));
     48     }
     49     {
     50         std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
     51         std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
     52         for (int i = 1; i <= 3; ++i)
     53         {
     54             l.push_back(i);
     55             lo.push_back(i);
     56         }
     57         std::list<MoveOnly, other_allocator<MoveOnly> > l2(std::move(l), other_allocator<MoveOnly>(4));
     58         assert(l2 == lo);
     59         assert(!l.empty());
     60         assert(l2.get_allocator() == other_allocator<MoveOnly>(4));
     61     }
     62 #if __cplusplus >= 201103L
     63     {
     64         std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
     65         std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
     66         for (int i = 1; i <= 3; ++i)
     67         {
     68             l.push_back(i);
     69             lo.push_back(i);
     70         }
     71         std::list<MoveOnly, min_allocator<MoveOnly> > l2(std::move(l), min_allocator<MoveOnly>());
     72         assert(l2 == lo);
     73         assert(l.empty());
     74         assert(l2.get_allocator() == min_allocator<MoveOnly>());
     75     }
     76 #endif
     77 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     78 }
     79