assign_iter_iter.pass.cpp (1802B)
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 // void assign(size_type n, const_reference v); 13 14 #include <vector> 15 #include <algorithm> 16 #include <cassert> 17 #include <iostream> 18 #include "test_macros.h" 19 #include "min_allocator.h" 20 #include "asan_testing.h" 21 #include "test_iterators.h" 22 #if TEST_STD_VER >= 11 23 #include "emplace_constructible.h" 24 #include "container_test_types.h" 25 #endif 26 27 28 void test_emplaceable_concept() { 29 #if TEST_STD_VER >= 11 30 int arr1[] = {42}; 31 int arr2[] = {1, 101, 42}; 32 { 33 using T = EmplaceConstructibleMoveableAndAssignable<int>; 34 using It = forward_iterator<int*>; 35 { 36 std::vector<T> v; 37 v.assign(It(arr1), It(std::end(arr1))); 38 assert(v[0].value == 42); 39 } 40 { 41 std::vector<T> v; 42 v.assign(It(arr2), It(std::end(arr2))); 43 assert(v[0].value == 1); 44 assert(v[1].value == 101); 45 assert(v[2].value == 42); 46 } 47 } 48 { 49 using T = EmplaceConstructibleMoveableAndAssignable<int>; 50 using It = input_iterator<int*>; 51 { 52 std::vector<T> v; 53 v.assign(It(arr1), It(std::end(arr1))); 54 assert(v[0].copied == 0); 55 assert(v[0].value == 42); 56 } 57 { 58 std::vector<T> v; 59 v.assign(It(arr2), It(std::end(arr2))); 60 //assert(v[0].copied == 0); 61 assert(v[0].value == 1); 62 //assert(v[1].copied == 0); 63 assert(v[1].value == 101); 64 assert(v[2].copied == 0); 65 assert(v[2].value == 42); 66 } 67 } 68 #endif 69 } 70 71 72 73 int main() 74 { 75 test_emplaceable_concept(); 76 }