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// <shared_mutex>
11
12// template <class Mutex> class shared_lock;
13
14// void swap(shared_lock& u) noexcept;
15
16#include <shared_mutex>
17#include <cassert>
18
19#if _LIBCPP_STD_VER > 11
20
21struct mutex
22{
23    void lock_shared() {}
24    void unlock_shared() {}
25};
26
27mutex m;
28
29#endif  // _LIBCPP_STD_VER > 11
30
31int main()
32{
33#if _LIBCPP_STD_VER > 11
34    std::shared_lock<mutex> lk1(m);
35    std::shared_lock<mutex> lk2;
36    lk1.swap(lk2);
37    assert(lk1.mutex() == nullptr);
38    assert(lk1.owns_lock() == false);
39    assert(lk2.mutex() == &m);
40    assert(lk2.owns_lock() == true);
41    static_assert(noexcept(lk1.swap(lk2)), "member swap must be noexcept");
42#endif  // _LIBCPP_STD_VER > 11
43}
44