• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   int state_;
21   static int next_;
22 
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) { return x.state_ == y; }
28 
operator =(int i)29   A& operator=(int i) {
30     state_ = i;
31     return *this;
32   }
33 };
34 
35 int A::next_ = 0;
36 
main()37 int 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