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// UNSUPPORTED: no-threads
10// UNSUPPORTED: c++03, c++11, c++14, c++17
11// XFAIL: availability-synchronization_library-missing
12
13// jthread(jthread&& x) noexcept;
14
15#include <cassert>
16#include <stop_token>
17#include <thread>
18#include <type_traits>
19#include <utility>
20
21#include "make_test_thread.h"
22#include "test_macros.h"
23
24static_assert(std::is_nothrow_move_constructible_v<std::jthread>);
25
26int main(int, char**) {
27 {
28 // x.get_id() == id() and get_id() returns the value of x.get_id() prior
29 // to the start of construction.
30 std::jthread j1 = support::make_test_jthread([] {});
31 auto id1 = j1.get_id();
32
33 std::jthread j2(std::move(j1));
34 assert(j1.get_id() == std::jthread::id());
35 assert(j2.get_id() == id1);
36 }
37
38 {
39 // ssource has the value of x.ssource prior to the start of construction
40 // and x.ssource.stop_possible() is false.
41 std::jthread j1 = support::make_test_jthread([] {});
42 auto ss1 = j1.get_stop_source();
43
44 std::jthread j2(std::move(j1));
45 assert(ss1 == j2.get_stop_source());
46 assert(!j1.get_stop_source().stop_possible());
47 assert(j2.get_stop_source().stop_possible());
48 }
49
50 return 0;
51}
52

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of libcxx/test/std/thread/thread.jthread/cons.move.pass.cpp