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// <memory> 11 12// template <class InputIterator, class ForwardIterator> 13// ForwardIterator 14// uninitialized_copy(InputIterator first, InputIterator last, 15// ForwardIterator result); 16 17#include <memory> 18#include <cassert> 19 20struct B 21{ 22 static int count_; 23 int data_; 24 explicit B() : data_(1) {} 25 B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;} 26 ~B() {data_ = 0;} 27}; 28 29int B::count_ = 0; 30 31int main() 32{ 33 const int N = 5; 34 char pool[sizeof(B)*N] = {0}; 35 B* bp = (B*)pool; 36 B b[N]; 37 try 38 { 39 std::uninitialized_copy(b, b+N, bp); 40 assert(false); 41 } 42 catch (...) 43 { 44 for (int i = 0; i < N; ++i) 45 assert(bp[i].data_ == 0); 46 } 47 B::count_ = 0; 48 std::uninitialized_copy(b, b+2, bp); 49 for (int i = 0; i < 2; ++i) 50 assert(bp[i].data_ == 1); 51} 52