]>
Commit | Line | Data |
---|---|---|
8868286e | 1 | // { dg-options "-std=gnu++11" } |
3b7d65ec | 2 | |
f1717362 | 3 | // Copyright (C) 2008-2016 Free Software Foundation, Inc. |
3b7d65ec | 4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
6bc9506f | 8 | // Free Software Foundation; either version 3, or (at your option) |
3b7d65ec | 9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
6bc9506f | 17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
3b7d65ec | 19 | |
20 | // 20.8.13.2 Template class shared_ptr [util.smartptr.shared] | |
21 | ||
22 | #include <memory> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | struct A { }; | |
26 | ||
27 | namespace std | |
28 | { | |
29 | template<> | |
30 | struct less<A*> : binary_function<A*,A*,bool> | |
31 | { | |
32 | static int count; | |
33 | bool operator()(A* l, A* r) { ++count; return l < r; } | |
34 | }; | |
35 | int less<A*>::count = 0; | |
36 | } | |
37 | ||
38 | // 20.8.13.2.7 shared_ptr comparison [util.smartptr.shared.cmp] | |
39 | ||
40 | ||
41 | int | |
42 | test01() | |
43 | { | |
9ad39aef | 44 | bool test __attribute__((unused)) = true; |
45 | ||
3b7d65ec | 46 | std::less<std::shared_ptr<A>> less; |
47 | // test empty shared_ptrs compare equivalent | |
48 | std::shared_ptr<A> p1; | |
49 | std::shared_ptr<A> p2; | |
50 | VERIFY( !less(p1, p2) && !less(p2, p1) ); | |
51 | VERIFY( std::less<A*>::count == 2 ); | |
52 | return 0; | |
53 | } | |
54 | ||
55 | ||
56 | // Construction from pointer | |
57 | int | |
58 | test02() | |
59 | { | |
9ad39aef | 60 | bool test __attribute__((unused)) = true; |
61 | ||
3b7d65ec | 62 | std::less<std::shared_ptr<A>> less; |
63 | ||
64 | std::shared_ptr<A> empty; | |
65 | std::shared_ptr<A> p1(new A); | |
66 | std::shared_ptr<A> p2(new A); | |
67 | ||
68 | VERIFY( less(p1, p2) || less(p2, p1) ); | |
69 | VERIFY( !(less(p1, p2) && less(p2, p1)) ); | |
70 | ||
71 | p1.reset(); | |
72 | VERIFY( !less(p1, empty) && !less(empty, p1) ); | |
73 | ||
74 | p2.reset(); | |
75 | VERIFY( !less(p1, p2) && !less(p2, p1) ); | |
76 | ||
77 | return 0; | |
78 | } | |
79 | ||
80 | // Aliasing | |
81 | int | |
82 | test03() | |
83 | { | |
9ad39aef | 84 | bool test __attribute__((unused)) = true; |
85 | ||
3b7d65ec | 86 | std::less<std::shared_ptr<A>> less; |
87 | ||
88 | A a; | |
89 | std::shared_ptr<A> p1(new A); | |
90 | std::shared_ptr<A> p2(p1, &a); | |
91 | VERIFY( less(p1, p2) || less(p2, p1) ); | |
92 | ||
93 | return 0; | |
94 | } | |
95 | int | |
96 | main() | |
97 | { | |
98 | test01(); | |
99 | test02(); | |
100 | test03(); | |
101 | return 0; | |
102 | } |