uninitialized_fill_n.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <memory> 11 12// template <class ForwardIterator, class Size, class T> 13// void 14// uninitialized_fill_n(ForwardIterator first, Size n, const T& x); 15 16#include <memory> 17#include <cassert> 18 19struct B 20{ 21 static int count_; 22 int data_; 23 explicit B() : data_(1) {} 24 B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;} 25 ~B() {data_ = 0;} 26}; 27 28int B::count_ = 0; 29 30int main() 31{ 32 const int N = 5; 33 char pool[sizeof(B)*N] = {0}; 34 B* bp = (B*)pool; 35 try 36 { 37 std::uninitialized_fill_n(bp, 5, B()); 38 assert(false); 39 } 40 catch (...) 41 { 42 for (int i = 0; i < N; ++i) 43 assert(bp[i].data_ == 0); 44 } 45 B::count_ = 0; 46 std::uninitialized_fill_n(bp, 2, B()); 47 for (int i = 0; i < 2; ++i) 48 assert(bp[i].data_ == 1); 49} 50