insert_iter_rvalue.pass.cpp (2138B)
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 // iterator insert(const_iterator position, value_type&& x); 15 16 #include <vector> 17 #include <cassert> 18 19 #include "test_macros.h" 20 #include "test_allocator.h" 21 #include "MoveOnly.h" 22 #include "min_allocator.h" 23 #include "asan_testing.h" 24 25 int main() 26 { 27 { 28 std::vector<MoveOnly> v(100); 29 std::vector<MoveOnly>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); 30 assert(v.size() == 101); 31 assert(is_contiguous_container_asan_correct(v)); 32 assert(i == v.begin() + 10); 33 int j; 34 for (j = 0; j < 10; ++j) 35 assert(v[j] == MoveOnly()); 36 assert(v[j] == MoveOnly(3)); 37 for (++j; j < 101; ++j) 38 assert(v[j] == MoveOnly()); 39 } 40 { 41 std::vector<MoveOnly, limited_allocator<MoveOnly, 300> > v(100); 42 std::vector<MoveOnly, limited_allocator<MoveOnly, 300> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); 43 assert(v.size() == 101); 44 assert(is_contiguous_container_asan_correct(v)); 45 assert(i == v.begin() + 10); 46 int j; 47 for (j = 0; j < 10; ++j) 48 assert(v[j] == MoveOnly()); 49 assert(v[j] == MoveOnly(3)); 50 for (++j; j < 101; ++j) 51 assert(v[j] == MoveOnly()); 52 } 53 { 54 std::vector<MoveOnly, min_allocator<MoveOnly>> v(100); 55 std::vector<MoveOnly, min_allocator<MoveOnly>>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); 56 assert(v.size() == 101); 57 assert(is_contiguous_container_asan_correct(v)); 58 assert(i == v.begin() + 10); 59 int j; 60 for (j = 0; j < 10; ++j) 61 assert(v[j] == MoveOnly()); 62 assert(v[j] == MoveOnly(3)); 63 for (++j; j < 101; ++j) 64 assert(v[j] == MoveOnly()); 65 } 66 }