43 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// template <class Mutex>14// void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y);15 16#include <cassert>17#include <memory>18#include <mutex>19 20#include "checking_mutex.h"21#include "test_macros.h"22 23#if TEST_STD_VER >= 1124static_assert(noexcept(swap(std::declval<std::unique_lock<checking_mutex>&>(),25 std::declval<std::unique_lock<checking_mutex>&>())),26 "");27#endif28 29int main(int, char**) {30 checking_mutex mux;31 std::unique_lock<checking_mutex> lock1(mux);32 std::unique_lock<checking_mutex> lock2;33 34 swap(lock1, lock2);35 36 assert(lock1.mutex() == nullptr);37 assert(!lock1.owns_lock());38 assert(lock2.mutex() == std::addressof(mux));39 assert(lock2.owns_lock() == true);40 41 return 0;42}43