49 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// UNSUPPORTED: no-threads10// UNSUPPORTED: c++03, c++11, c++14, c++1711 12// void swap(stop_source& rhs) noexcept;13 14#include <cassert>15#include <concepts>16#include <stop_token>17#include <type_traits>18 19#include "test_macros.h"20 21template <class T>22concept IsNoThrowMemberSwappable = requires(T& t) {23 { t.swap(t) } noexcept;24};25 26static_assert(IsNoThrowMemberSwappable<std::stop_source>);27 28int main(int, char**) {29 {30 std::stop_source ss1;31 std::stop_source ss2;32 33 assert(ss1 != ss2);34 35 ss2.request_stop();36 37 assert(!ss1.stop_requested());38 assert(ss2.stop_requested());39 40 ss1.swap(ss2);41 42 assert(ss1 != ss2);43 assert(ss1.stop_requested());44 assert(!ss2.stop_requested());45 }46 47 return 0;48}49