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
11
12// <future>
13
14// class packaged_task<R(ArgTypes...)>
15
16// packaged_task& operator=(packaged_task&& other);
17
18#include <future>
19#include <cassert>
20
21#include "test_macros.h"
22
23class A
24{
25 long data_;
26
27public:
28 explicit A(long i) : data_(i) {}
29
30 long operator()(long i, long j) const {return data_ + i + j;}
31};
32
33int main(int, char**)
34{
35 {
36 std::packaged_task<double(int, char)> p0(A(5));
37 std::packaged_task<double(int, char)> p;
38 p = std::move(p0);
39 assert(!p0.valid());
40 assert(p.valid());
41 std::future<double> f = p.get_future();
42 p(3, 97);
43 assert(f.get() == 105.0);
44 }
45 {
46 std::packaged_task<double(int, char)> p0;
47 std::packaged_task<double(int, char)> p;
48 p = std::move(p0);
49 assert(!p0.valid());
50 assert(!p.valid());
51 }
52
53 return 0;
54}
55

source code of libcxx/test/std/thread/futures/futures.task/futures.task.members/assign_move.pass.cpp