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