int main() { { const int N = 5; char pool[sizeof(B)*N] = {0}; B* bp = (B*)pool; assert(B::population_ == 0); try { std::uninitialized_fill(bp, bp+N, B()); assert(false); } catch (...) { assert(B::population_ == 0); } B::count_ = 0; std::uninitialized_fill(bp, bp+2, B()); for (int i = 0; i < 2; ++i) assert(bp[i].data_ == 1); assert(B::population_ == 2); } { const int N = 5; char pool[N*sizeof(Nasty)] = {0}; Nasty* bp = (Nasty*)pool; Nasty::counter_ = 23; std::uninitialized_fill(bp, bp+N, Nasty()); for (int i = 0; i < N; ++i) assert(bp[i].i_ == 23); } }
int main(int, char**) { { const int N = 5; char pool[sizeof(B)*N] = {0}; B* bp = (B*)pool; assert(B::population_ == 0); #ifndef TEST_HAS_NO_EXCEPTIONS try { std::uninitialized_fill_n(bp, 5, B()); assert(false); } catch (...) { assert(B::population_ == 0); } #endif B::count_ = 0; B* r = std::uninitialized_fill_n(bp, 2, B()); assert(r == bp + 2); for (int i = 0; i < 2; ++i) assert(bp[i].data_ == 1); assert(B::population_ == 2); } { { const int N = 5; char pool[N*sizeof(Nasty)] = {0}; Nasty* bp = (Nasty*)pool; Nasty::counter_ = 23; std::uninitialized_fill_n(bp, N, Nasty()); for (int i = 0; i < N; ++i) assert(bp[i].i_ == 23); } } return 0; }