libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

merge.pass.cpp (1532B)


      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 // void merge(list& x);
     13 // If (&addressof(x) == this) does nothing; otherwise ...
     14 
     15 #include <list>
     16 #include <cassert>
     17 
     18 #include "min_allocator.h"
     19 
     20 int main()
     21 {
     22     {
     23     int a1[] = {1, 3, 7, 9, 10};
     24     int a2[] = {0, 2, 4, 5, 6, 8, 11};
     25     int a3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
     26     std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
     27     std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
     28     c1.merge(c2);
     29     assert(c1 == std::list<int>(a3, a3+sizeof(a3)/sizeof(a3[0])));
     30     assert(c2.empty());
     31     }
     32 
     33     {
     34     int a1[] = {1, 3, 7, 9, 10};
     35     std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
     36     c1.merge(c1);
     37     assert((c1 == std::list<int>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
     38     }
     39 
     40 #if TEST_STD_VER >= 11
     41     {
     42     int a1[] = {1, 3, 7, 9, 10};
     43     int a2[] = {0, 2, 4, 5, 6, 8, 11};
     44     int a3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
     45     std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
     46     std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
     47     c1.merge(c2);
     48     assert((c1 == std::list<int, min_allocator<int>>(a3, a3+sizeof(a3)/sizeof(a3[0]))));
     49     assert(c2.empty());
     50     }
     51 #endif
     52 }