1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <memory>
10 
11 // unique_ptr
12 
13 // test op[](size_t)
14 
15 #include <memory>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 
20 class A {
21   int state_;
22   static int next_;
23 
24 public:
25   A() : state_(++next_) {}
26   int get() const { return state_; }
27 
28   friend bool operator==(const A& x, int y) { return x.state_ == y; }
29 
30   A& operator=(int i) {
31     state_ = i;
32     return *this;
33   }
34 };
35 
36 int A::next_ = 0;
37 
38 int main(int, char**) {
39   std::unique_ptr<A[]> p(new A[3]);
40   assert(p[0] == 1);
41   assert(p[1] == 2);
42   assert(p[2] == 3);
43   p[0] = 3;
44   p[1] = 2;
45   p[2] = 1;
46   assert(p[0] == 3);
47   assert(p[1] == 2);
48   assert(p[2] == 1);
49 
50   return 0;
51 }
52