blob: f77d6c75e17a402dec93df1ec54ba2d6c8b9933c [file] [log] [blame]
Marshall Clowdbaf7a02015-05-10 13:14:08 +00001//===----------------------------------------------------------------------===//
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
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{
Marshall Clowdbaf7a02015-05-10 13:14:08 +000032 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);
Marshall Clowdbaf7a02015-05-10 13:14:08 +000037 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);
Marshall Clowdbaf7a02015-05-10 13:14:08 +000043 }
Marshall Clowdbaf7a02015-05-10 13:14:08 +000044}