Home | History | Annotate | Download | only in vector.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 // <vector>
     11 
     12 // vector(vector&& c);
     13 
     14 #include <vector>
     15 #include <cassert>
     16 #include "MoveOnly.h"
     17 #include "test_allocator.h"
     18 #include "min_allocator.h"
     19 #include "asan_testing.h"
     20 
     21 int main()
     22 {
     23 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     24     {
     25         std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
     26         std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
     27         assert(is_contiguous_container_asan_correct(l));
     28         assert(is_contiguous_container_asan_correct(lo));
     29         for (int i = 1; i <= 3; ++i)
     30         {
     31             l.push_back(i);
     32             lo.push_back(i);
     33         }
     34         assert(is_contiguous_container_asan_correct(l));
     35         assert(is_contiguous_container_asan_correct(lo));
     36         std::vector<MoveOnly, test_allocator<MoveOnly> > l2 = std::move(l);
     37         assert(l2 == lo);
     38         assert(l.empty());
     39         assert(l2.get_allocator() == lo.get_allocator());
     40         assert(is_contiguous_container_asan_correct(l2));
     41     }
     42     {
     43         std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
     44         std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
     45         assert(is_contiguous_container_asan_correct(l));
     46         assert(is_contiguous_container_asan_correct(lo));
     47         for (int i = 1; i <= 3; ++i)
     48         {
     49             l.push_back(i);
     50             lo.push_back(i);
     51         }
     52         assert(is_contiguous_container_asan_correct(l));
     53         assert(is_contiguous_container_asan_correct(lo));
     54         std::vector<MoveOnly, other_allocator<MoveOnly> > l2 = std::move(l);
     55         assert(l2 == lo);
     56         assert(l.empty());
     57         assert(l2.get_allocator() == lo.get_allocator());
     58         assert(is_contiguous_container_asan_correct(l2));
     59     }
     60     {
     61         int a1[] = {1, 3, 7, 9, 10};
     62         std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
     63         assert(is_contiguous_container_asan_correct(c1));
     64         std::vector<int>::const_iterator i = c1.begin();
     65         std::vector<int> c2 = std::move(c1);
     66         assert(is_contiguous_container_asan_correct(c2));
     67         std::vector<int>::iterator j = c2.erase(i);
     68         assert(*j == 3);
     69         assert(is_contiguous_container_asan_correct(c2));
     70     }
     71 #if __cplusplus >= 201103L
     72     {
     73         std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
     74         std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
     75         assert(is_contiguous_container_asan_correct(l));
     76         assert(is_contiguous_container_asan_correct(lo));
     77         for (int i = 1; i <= 3; ++i)
     78         {
     79             l.push_back(i);
     80             lo.push_back(i);
     81         }
     82         assert(is_contiguous_container_asan_correct(l));
     83         assert(is_contiguous_container_asan_correct(lo));
     84         std::vector<MoveOnly, min_allocator<MoveOnly> > l2 = std::move(l);
     85         assert(l2 == lo);
     86         assert(l.empty());
     87         assert(l2.get_allocator() == lo.get_allocator());
     88         assert(is_contiguous_container_asan_correct(l2));
     89     }
     90     {
     91         int a1[] = {1, 3, 7, 9, 10};
     92         std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
     93         assert(is_contiguous_container_asan_correct(c1));
     94         std::vector<int, min_allocator<int>>::const_iterator i = c1.begin();
     95         std::vector<int, min_allocator<int>> c2 = std::move(c1);
     96         assert(is_contiguous_container_asan_correct(c2));
     97         std::vector<int, min_allocator<int>>::iterator j = c2.erase(i);
     98         assert(*j == 3);
     99         assert(is_contiguous_container_asan_correct(c2));
    100     }
    101 #endif
    102 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    103 }
    104