Debian Codegraph @

libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.obs/op_bool.pass.cpp

raw
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
11 // <mutex>
12
13 // template <class Mutex> class unique_lock;
14
15 // explicit operator bool() const noexcept;
16
17 #include <mutex>
18 #include <cassert>
19 #include <type_traits>
20
21 #include "test_macros.h"
22
23 std::mutex m;
24
25 int main(int, char**)
26 {
27 static_assert(std::is_constructible<bool, std::unique_lock<std::mutex> >::value, "");
28 static_assert(!std::is_convertible<std::unique_lock<std::mutex>, bool>::value, "");
29
30 std::unique_lock<std::mutex> lk0;
31 assert(static_cast<bool>(lk0) == false);
32 std::unique_lock<std::mutex> lk1(m);
33 assert(static_cast<bool>(lk1) == true);
34 lk1.unlock();
35 assert(static_cast<bool>(lk1) == false);
36 ASSERT_NOEXCEPT(static_cast<bool>(lk0));
37
38 return 0;
39 }