42 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <mutex>10 11// template <class Mutex> class unique_lock;12 13// void swap(unique_lock& u);14 15#include <cassert>16#include <memory>17#include <mutex>18 19#include "checking_mutex.h"20#include "test_macros.h"21 22#if TEST_STD_VER >= 1123static_assert(24 noexcept(std::declval<std::unique_lock<checking_mutex>&>().swap(std::declval<std::unique_lock<checking_mutex>&>())),25 "");26#endif27 28int main(int, char**) {29 checking_mutex mux;30 std::unique_lock<checking_mutex> lock1(mux);31 std::unique_lock<checking_mutex> lock2;32 33 lock1.swap(lock2);34 35 assert(lock1.mutex() == nullptr);36 assert(!lock1.owns_lock());37 assert(lock2.mutex() == std::addressof(mux));38 assert(lock2.owns_lock() == true);39 40 return 0;41}42