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