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