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