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// XFAIL: libcpp-no-exceptions 11// <memory> 12 13// template <class InputIterator, class ForwardIterator> 14// ForwardIterator 15// uninitialized_copy(InputIterator first, InputIterator last, 16// ForwardIterator result); 17 18#include <memory> 19#include <cassert> 20 21struct B 22{ 23 static int count_; 24 static int population_; 25 int data_; 26 explicit B() : data_(1) { ++population_; } 27 B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; } 28 ~B() {data_ = 0; --population_; } 29}; 30 31int B::count_ = 0; 32int B::population_ = 0; 33 34struct Nasty 35{ 36 Nasty() : i_ ( counter_++ ) {} 37 Nasty * operator &() const { return NULL; } 38 int i_; 39 static int counter_; 40}; 41 42int Nasty::counter_ = 0; 43 44int main() 45{ 46 { 47 const int N = 5; 48 char pool[sizeof(B)*N] = {0}; 49 B* bp = (B*)pool; 50 B b[N]; 51 assert(B::population_ == N); 52 try 53 { 54 std::uninitialized_copy(b, b+N, bp); 55 assert(false); 56 } 57 catch (...) 58 { 59 assert(B::population_ == N); 60 } 61 B::count_ = 0; 62 std::uninitialized_copy(b, b+2, bp); 63 for (int i = 0; i < 2; ++i) 64 assert(bp[i].data_ == 1); 65 assert(B::population_ == N + 2); 66 } 67 68 { 69 const int N = 5; 70 char pool[sizeof(Nasty)*N] = {0}; 71 Nasty * p = (Nasty *) pool; 72 Nasty arr[N]; 73 std::uninitialized_copy(arr, arr+N, p); 74 for (int i = 0; i < N; ++i) { 75 assert(arr[i].i_ == i); 76 assert( p[i].i_ == i); 77 } 78 } 79 80} 81