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++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 
21 #include "test_macros.h"
22 
23 struct M {
24     void lock_shared() {}
25     void unlock_shared() {}
26 };
27 
28 int main(int, char**)
29 {
30     static_assert(std::is_constructible<bool, std::shared_lock<M>>::value, "");
31     static_assert(!std::is_convertible<std::shared_lock<M>, bool>::value, "");
32 
33     M m;
34     std::shared_lock<M> lk0;
35     assert(static_cast<bool>(lk0) == false);
36     std::shared_lock<M> lk1(m);
37     assert(static_cast<bool>(lk1) == true);
38     lk1.unlock();
39     assert(static_cast<bool>(lk1) == false);
40     ASSERT_NOEXCEPT(static_cast<bool>(lk0));
41 
42     return 0;
43 }
44