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// <mutex>
10
11// template <class Mutex> class unique_lock;
12
13// unique_lock(mutex_type& m, defer_lock_t);
14
15#include <cassert>
16#include <memory>
17#include <mutex>
18#include <type_traits>
19
20#include "checking_mutex.h"
21#include "test_macros.h"
22
23#if TEST_STD_VER >= 11
24static_assert(
25 std::is_nothrow_constructible<std::unique_lock<checking_mutex>, checking_mutex&, std::defer_lock_t>::value, "");
26#endif
27
28int main(int, char**) {
29 checking_mutex m;
30 std::unique_lock<checking_mutex> lk(m, std::defer_lock_t());
31 assert(m.last_try == checking_mutex::none);
32 assert(lk.mutex() == std::addressof(m));
33 assert(lk.owns_lock() == false);
34
35 return 0;
36}
37

source code of libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp