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// <forward_list> 11 12// void resize(size_type n, const value_type& v); 13 14#include <forward_list> 15#include <cassert> 16 17#include "test_macros.h" 18#include "DefaultOnly.h" 19#include "min_allocator.h" 20 21#if TEST_STD_VER >= 11 22#include "container_test_types.h" 23#endif 24 25int main() 26{ 27 { 28 typedef int T; 29 typedef std::forward_list<T> C; 30 const T t[] = {0, 1, 2, 3, 4}; 31 C c(std::begin(t), std::end(t)); 32 33 c.resize(3, 10); 34 assert(distance(c.begin(), c.end()) == 3); 35 assert(*next(c.begin(), 0) == 0); 36 assert(*next(c.begin(), 1) == 1); 37 assert(*next(c.begin(), 2) == 2); 38 39 c.resize(6, 10); 40 assert(distance(c.begin(), c.end()) == 6); 41 assert(*next(c.begin(), 0) == 0); 42 assert(*next(c.begin(), 1) == 1); 43 assert(*next(c.begin(), 2) == 2); 44 assert(*next(c.begin(), 3) == 10); 45 assert(*next(c.begin(), 4) == 10); 46 assert(*next(c.begin(), 5) == 10); 47 48 c.resize(6, 12); 49 assert(distance(c.begin(), c.end()) == 6); 50 assert(*next(c.begin(), 0) == 0); 51 assert(*next(c.begin(), 1) == 1); 52 assert(*next(c.begin(), 2) == 2); 53 assert(*next(c.begin(), 3) == 10); 54 assert(*next(c.begin(), 4) == 10); 55 assert(*next(c.begin(), 5) == 10); 56 } 57#if TEST_STD_VER >= 11 58 { 59 typedef int T; 60 typedef std::forward_list<T, min_allocator<T>> C; 61 const T t[] = {0, 1, 2, 3, 4}; 62 C c(std::begin(t), std::end(t)); 63 64 c.resize(3, 10); 65 assert(distance(c.begin(), c.end()) == 3); 66 assert(*next(c.begin(), 0) == 0); 67 assert(*next(c.begin(), 1) == 1); 68 assert(*next(c.begin(), 2) == 2); 69 70 c.resize(6, 10); 71 assert(distance(c.begin(), c.end()) == 6); 72 assert(*next(c.begin(), 0) == 0); 73 assert(*next(c.begin(), 1) == 1); 74 assert(*next(c.begin(), 2) == 2); 75 assert(*next(c.begin(), 3) == 10); 76 assert(*next(c.begin(), 4) == 10); 77 assert(*next(c.begin(), 5) == 10); 78 79 c.resize(6, 12); 80 assert(distance(c.begin(), c.end()) == 6); 81 assert(*next(c.begin(), 0) == 0); 82 assert(*next(c.begin(), 1) == 1); 83 assert(*next(c.begin(), 2) == 2); 84 assert(*next(c.begin(), 3) == 10); 85 assert(*next(c.begin(), 4) == 10); 86 assert(*next(c.begin(), 5) == 10); 87 } 88 { 89 // Test that the allocator's construct method is being used to 90 // construct the new elements and that it's called exactly N times. 91 typedef int T; 92 typedef std::forward_list<int, ContainerTestAllocator<int, int>> Container; 93 ConstructController* cc = getConstructController(); 94 cc->reset(); 95 { 96 Container c; 97 cc->expect<int const&>(6); 98 c.resize(6, 42); 99 assert(!cc->unchecked()); 100 } 101 } 102#endif 103} 104