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 class A { 19 int state_; 20 static int next_; 21 22 public: 23 A() : state_(++next_) {} 24 int get() const { return state_; } 25 26 friend bool operator==(const A& x, int y) { return x.state_ == y; } 27 28 A& operator=(int i) { 29 state_ = i; 30 return *this; 31 } 32 }; 33 34 int A::next_ = 0; 35 36 int main(int, char**) { 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 return 0; 49 } 50