1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // UNSUPPORTED: libcpp-has-no-threads 10 // UNSUPPORTED: c++98, c++03, c++11 11 12 // <shared_mutex> 13 14 // template <class Mutex> class shared_lock; 15 16 // template <class Mutex> 17 // void swap(shared_lock<Mutex>& x, shared_lock<Mutex>& y) noexcept; 18 19 #include <shared_mutex> 20 #include <cassert> 21 22 struct mutex 23 { 24 void lock_shared() {} 25 void unlock_shared() {} 26 }; 27 28 mutex m; 29 30 int main(int, char**) 31 { 32 std::shared_lock<mutex> lk1(m); 33 std::shared_lock<mutex> lk2; 34 swap(lk1, 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(swap(lk1, lk2)), "non-member swap must be noexcept"); 40 41 return 0; 42 } 43