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// <memory>
11
12// unique_ptr
13
14// test op[](size_t)
15
16#include <memory>
17#include <cassert>
18
19class A {
20  int state_;
21  static int next_;
22
23public:
24  A() : state_(++next_) {}
25  int get() const { return state_; }
26
27  friend bool operator==(const A& x, int y) { return x.state_ == y; }
28
29  A& operator=(int i) {
30    state_ = i;
31    return *this;
32  }
33};
34
35int A::next_ = 0;
36
37int main() {
38  std::unique_ptr<A[]> p(new A[3]);
39  assert(p[0] == 1);
40  assert(p[1] == 2);
41  assert(p[2] == 3);
42  p[0] = 3;
43  p[1] = 2;
44  p[2] = 1;
45  assert(p[0] == 3);
46  assert(p[1] == 2);
47  assert(p[2] == 1);
48}
49