51 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// friend void swap(stop_token& x, stop_token& y) 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 IsNoThrowFreeSwappable = requires(T& t) {23 { swap(t, t) } noexcept;24};25 26static_assert(IsNoThrowFreeSwappable<std::stop_token>);27 28int main(int, char**) {29 {30 std::stop_token st1;31 32 std::stop_source source;33 auto st2 = source.get_token();34 35 assert(st1 != st2);36 37 source.request_stop();38 39 assert(!st1.stop_requested());40 assert(st2.stop_requested());41 42 swap(st1, st2);43 44 assert(st1 != st2);45 assert(st1.stop_requested());46 assert(!st2.stop_requested());47 }48 49 return 0;50}51