raw_storag_iterator.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// raw_storage_iterator 11 12#include <memory> 13#include <type_traits> 14#include <cassert> 15 16int A_constructed = 0; 17 18struct A 19{ 20 int data_; 21public: 22 explicit A(int i) : data_(i) {++A_constructed;} 23 24 A(const A& a) : data_(a.data_) {++A_constructed;} 25 ~A() {--A_constructed; data_ = 0;} 26 27 bool operator==(int i) const {return data_ == i;} 28}; 29 30int main() 31{ 32 typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type 33 Storage; 34 Storage buffer; 35 std::raw_storage_iterator<A*, A> it((A*)&buffer); 36 assert(A_constructed == 0); 37 for (int i = 0; i < 3; ++i) 38 { 39 *it++ = A(i+1); 40 A* ap = (A*)&buffer + i; 41 assert(*ap == i+1); 42 assert(A_constructed == i+1); 43 } 44} 45