2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / weak_ptr / observers / owner_before.cc
blob1081f93d338979df1fb96e0c48e3c462f07bb004
1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2008, 2009 Free Software Foundation
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
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 20.8.13.3 Template class weak_ptr [util.smartptr.weak]
22 #include <memory>
23 #include <testsuite_hooks.h>
25 struct A { };
26 struct B { };
28 // 20.6.6.3.5 weak_ptr observers [util.smartptr.weak.obs]
30 int
31 test01()
33 bool test __attribute__((unused)) = true;
35 // test empty weak_ptrs compare equivalent
36 std::weak_ptr<A> p1;
37 std::weak_ptr<B> p2;
38 VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) );
40 std::shared_ptr<B> p3;
41 VERIFY( !p1.owner_before(p3) && !p3.owner_before(p1) );
43 return 0;
47 int
48 test02()
50 bool test __attribute__((unused)) = true;
52 std::shared_ptr<A> a0;
53 std::weak_ptr<A> w0(a0);
55 std::shared_ptr<A> a1(new A);
56 std::weak_ptr<A> w1(a1);
57 VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) );
59 VERIFY( w1.owner_before(w0) || w0.owner_before(w1) );
60 VERIFY( !(w1.owner_before(w0) && w0.owner_before(w1)) );
62 VERIFY( w1.owner_before(a0) || a0.owner_before(w1) );
63 VERIFY( !(w1.owner_before(a0) && a0.owner_before(w1)) );
65 std::shared_ptr<B> b1(new B);
66 VERIFY( w1.owner_before(b1) || b1.owner_before(w1) );
68 return 0;
71 int
72 main()
74 test01();
75 test02();
76 return 0;