• 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 // template <class T1, class D1, class T2, class D2>
15 //   bool
16 //   operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
17 
18 // template <class T1, class D1, class T2, class D2>
19 //   bool
20 //   operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
21 
22 #include <memory>
23 #include <cassert>
24 
25 #include "deleter_types.h"
26 
27 struct A
28 {
29     static int count;
AA30     A() {++count;}
AA31     A(const A&) {++count;}
~AA32     virtual ~A() {--count;}
33 };
34 
35 int A::count = 0;
36 
37 struct B
38     : public A
39 {
40     static int count;
BB41     B() {++count;}
BB42     B(const B&) {++count;}
~BB43     virtual ~B() {--count;}
44 };
45 
46 int B::count = 0;
47 
main()48 int main()
49 {
50     {
51     const std::unique_ptr<A, Deleter<A> > p1(new A);
52     const std::unique_ptr<A, Deleter<A> > p2(new A);
53     assert(!(p1 == p2));
54     assert(p1 != p2);
55     }
56     {
57     const std::unique_ptr<A, Deleter<A> > p1(new A);
58     const std::unique_ptr<B, Deleter<B> > p2(new B);
59     assert(!(p1 == p2));
60     assert(p1 != p2);
61     }
62     {
63     const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
64     const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]);
65     assert(!(p1 == p2));
66     assert(p1 != p2);
67     }
68     {
69     const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
70     const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]);
71     assert(!(p1 == p2));
72     assert(p1 != p2);
73     }
74     {
75     const std::unique_ptr<A, Deleter<A> > p1;
76     const std::unique_ptr<A, Deleter<A> > p2;
77     assert(p1 == p2);
78     assert(!(p1 != p2));
79     }
80     {
81     const std::unique_ptr<A, Deleter<A> > p1;
82     const std::unique_ptr<B, Deleter<B> > p2;
83     assert(p1 == p2);
84     assert(!(p1 != p2));
85     }
86 }
87