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