1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2008 Free Software Foundation
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
8 // Free Software Foundation; either version 2, or (at your option)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // 20.8.13.2 Template class shared_ptr [util.smartptr.shared]
24 #include <testsuite_hooks.h>
31 struct less<A*> : binary_function<A*,A*,bool>
34 bool operator()(A* l, A* r) { ++count; return l < r; }
36 int less<A*>::count = 0;
39 // 20.8.13.2.7 shared_ptr comparison [util.smartptr.shared.cmp]
45 std::less<std::shared_ptr<A>> less;
46 // test empty shared_ptrs compare equivalent
47 std::shared_ptr<A> p1;
48 std::shared_ptr<A> p2;
49 VERIFY( !less(p1, p2) && !less(p2, p1) );
50 VERIFY( std::less<A*>::count == 2 );
55 // Construction from pointer
59 std::less<std::shared_ptr<A>> less;
61 std::shared_ptr<A> empty;
62 std::shared_ptr<A> p1(new A);
63 std::shared_ptr<A> p2(new A);
65 VERIFY( less(p1, p2) || less(p2, p1) );
66 VERIFY( !(less(p1, p2) && less(p2, p1)) );
69 VERIFY( !less(p1, empty) && !less(empty, p1) );
72 VERIFY( !less(p1, p2) && !less(p2, p1) );
81 std::less<std::shared_ptr<A>> less;
84 std::shared_ptr<A> p1(new A);
85 std::shared_ptr<A> p2(p1, &a);
86 VERIFY( less(p1, p2) || less(p2, p1) );