libcxx

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

move_alloc.pass.cpp (3871B)


      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(vector&& c, const allocator_type& a);
     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         assert(is_contiguous_container_asan_correct(l));
     29         assert(is_contiguous_container_asan_correct(lo));
     30         for (int i = 1; i <= 3; ++i)
     31         {
     32             l.push_back(i);
     33             lo.push_back(i);
     34         }
     35         assert(is_contiguous_container_asan_correct(l));
     36         assert(is_contiguous_container_asan_correct(lo));
     37         std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(6));
     38         assert(l2 == lo);
     39         assert(!l.empty());
     40         assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
     41         assert(is_contiguous_container_asan_correct(l2));
     42     }
     43     {
     44         std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
     45         std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
     46         assert(is_contiguous_container_asan_correct(l));
     47         assert(is_contiguous_container_asan_correct(lo));
     48         for (int i = 1; i <= 3; ++i)
     49         {
     50             l.push_back(i);
     51             lo.push_back(i);
     52         }
     53         assert(is_contiguous_container_asan_correct(l));
     54         assert(is_contiguous_container_asan_correct(lo));
     55         std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(5));
     56         assert(l2 == lo);
     57         assert(l.empty());
     58         assert(l2.get_allocator() == test_allocator<MoveOnly>(5));
     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(std::move(l), other_allocator<MoveOnly>(4));
     74         assert(l2 == lo);
     75         assert(!l.empty());
     76         assert(l2.get_allocator() == other_allocator<MoveOnly>(4));
     77         assert(is_contiguous_container_asan_correct(l2));
     78     }
     79     {
     80         std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
     81         std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
     82         assert(is_contiguous_container_asan_correct(l));
     83         assert(is_contiguous_container_asan_correct(lo));
     84         for (int i = 1; i <= 3; ++i)
     85         {
     86             l.push_back(i);
     87             lo.push_back(i);
     88         }
     89         assert(is_contiguous_container_asan_correct(l));
     90         assert(is_contiguous_container_asan_correct(lo));
     91         std::vector<MoveOnly, min_allocator<MoveOnly> > l2(std::move(l), min_allocator<MoveOnly>());
     92         assert(l2 == lo);
     93         assert(l.empty());
     94         assert(l2.get_allocator() == min_allocator<MoveOnly>());
     95         assert(is_contiguous_container_asan_correct(l2));
     96     }
     97 }