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: no-threads 10 // UNSUPPORTED: c++03, c++11 11 12 // <shared_mutex> 13 14 // template <class Mutex> class shared_lock; 15 16 // explicit operator bool() const noexcept; 17 18 #include <shared_mutex> 19 #include <cassert> 20 #include <type_traits> 21 22 #include "test_macros.h" 23 24 struct M { lock_sharedM25 void lock_shared() {} unlock_sharedM26 void unlock_shared() {} 27 }; 28 main(int,char **)29int main(int, char**) 30 { 31 static_assert(std::is_constructible<bool, std::shared_lock<M>>::value, ""); 32 static_assert(!std::is_convertible<std::shared_lock<M>, bool>::value, ""); 33 34 M m; 35 std::shared_lock<M> lk0; 36 assert(static_cast<bool>(lk0) == false); 37 std::shared_lock<M> lk1(m); 38 assert(static_cast<bool>(lk1) == true); 39 lk1.unlock(); 40 assert(static_cast<bool>(lk1) == false); 41 ASSERT_NOEXCEPT(static_cast<bool>(lk0)); 42 43 return 0; 44 } 45