]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.runtime.pass.cpp
Vendor import of libc++ 4.0.0 release r297347:
[FreeBSD/FreeBSD.git] / test / std / utilities / smartptr / unique.ptr / unique.ptr.class / unique.ptr.observers / op_subscript.runtime.pass.cpp
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:
24   A() : state_(++next_) {}
25   int get() const { return state_; }
26
27   friend bool operator==(const A& x, int y) { return x.state_ == y; }
28
29   A& operator=(int i) {
30     state_ = i;
31     return *this;
32   }
33 };
34
35 int A::next_ = 0;
36
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 }