1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <vector> 10 11 // void assign(size_type n, const_reference v); 12 13 #include <vector> 14 #include <algorithm> 15 #include <cassert> 16 17 #include "test_macros.h" 18 #include "min_allocator.h" 19 #include "asan_testing.h" 20 is6(int x)21bool is6(int x) { return x == 6; } 22 23 template <typename Vec> test(Vec & v)24void test ( Vec &v ) 25 { 26 v.assign(5, 6); 27 assert(v.size() == 5); 28 assert(is_contiguous_container_asan_correct(v)); 29 assert(std::all_of(v.begin(), v.end(), is6)); 30 } 31 main(int,char **)32int main(int, char**) 33 { 34 { 35 typedef std::vector<int> V; 36 V d1; 37 V d2; 38 d2.reserve(10); // no reallocation during assign. 39 test(d1); 40 test(d2); 41 } 42 43 #if TEST_STD_VER >= 11 44 { 45 typedef std::vector<int, min_allocator<int>> V; 46 V d1; 47 V d2; 48 d2.reserve(10); // no reallocation during assign. 49 test(d1); 50 test(d2); 51 } 52 #endif 53 54 return 0; 55 } 56