libcxx

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

assign_move.pass.cpp (3767B)


      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 // UNSUPPORTED: c++98, c++03
     11 
     12 // <vector>
     13 
     14 // vector& operator=(vector&& c);
     15 
     16 #include <vector>
     17 #include <cassert>
     18 #include "MoveOnly.h"
     19 #include "test_allocator.h"
     20 #include "min_allocator.h"
     21 #include "asan_testing.h"
     22 
     23 int main()
     24 {
     25     {
     26         std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
     27         std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
     28         for (int i = 1; i <= 3; ++i)
     29         {
     30             l.push_back(i);
     31             lo.push_back(i);
     32         }
     33         assert(is_contiguous_container_asan_correct(l));
     34         assert(is_contiguous_container_asan_correct(lo));
     35         std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5));
     36         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, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
     44         std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_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, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6));
     55         l2 = std::move(l);
     56         assert(l2 == lo);
     57         assert(!l.empty());
     58         assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
     59         assert(is_contiguous_container_asan_correct(l2));
     60     }
     61     {
     62         std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
     63         std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
     64         assert(is_contiguous_container_asan_correct(l));
     65         assert(is_contiguous_container_asan_correct(lo));
     66         for (int i = 1; i <= 3; ++i)
     67         {
     68             l.push_back(i);
     69             lo.push_back(i);
     70         }
     71         assert(is_contiguous_container_asan_correct(l));
     72         assert(is_contiguous_container_asan_correct(lo));
     73         std::vector<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6));
     74         l2 = std::move(l);
     75         assert(l2 == lo);
     76         assert(l.empty());
     77         assert(l2.get_allocator() == lo.get_allocator());
     78         assert(is_contiguous_container_asan_correct(l2));
     79     }
     80     {
     81         std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
     82         std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
     83         assert(is_contiguous_container_asan_correct(l));
     84         assert(is_contiguous_container_asan_correct(lo));
     85         for (int i = 1; i <= 3; ++i)
     86         {
     87             l.push_back(i);
     88             lo.push_back(i);
     89         }
     90         assert(is_contiguous_container_asan_correct(l));
     91         assert(is_contiguous_container_asan_correct(lo));
     92         std::vector<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{});
     93         l2 = std::move(l);
     94         assert(l2 == lo);
     95         assert(l.empty());
     96         assert(l2.get_allocator() == lo.get_allocator());
     97         assert(is_contiguous_container_asan_correct(l2));
     98     }
     99 }