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