aboutsummaryrefslogtreecommitdiff
path: root/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp
blob: 5cd171a53021d236b876d3b5240513ba1d7fa85a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// <memory>

// weak_ptr

// template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept;

#include <memory>
#include <cassert>
#include "test_macros.h"

int main()
{
    const std::shared_ptr<int> p1(new int);
    const std::shared_ptr<int> p2 = p1;
    const std::shared_ptr<int> p3(new int);
    const std::weak_ptr<int> w1(p1);
    const std::weak_ptr<int> w2(p2);
    const std::weak_ptr<int> w3(p3);
    assert(!w1.owner_before(w2));
    assert(!w2.owner_before(w1));
    assert(w1.owner_before(w3) || w3.owner_before(w1));
    assert(w3.owner_before(w1) == w3.owner_before(w2));
//  change to 'ASSERT_NOEXCEPT' when LWG2942 is adopted
    LIBCPP_ASSERT_NOEXCEPT(w1.owner_before(w2));
}