blob: 27b620569b83f96865d942e57da3150369676144 [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{
32#if __cplusplus >= 201402L
33 typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type
34 Storage;
35 Storage buffer;
36 std::raw_storage_iterator<A*, A> it((A*)&buffer);
37 assert(A_constructed == 0);
38 assert(it.base() == (A*)&buffer);
39 for (int i = 0; i < 3; ++i)
40 {
41 *it++ = A(i+1);
42 A* ap = (A*)&buffer + i;
43 assert(*ap == i+1);
44 assert(A_constructed == i+1);
45 assert(it.base() == ap + 1); // next place to write
46 }
47#endif
48}