1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // UNSUPPORTED: libcpp-has-no-threads
11 // UNSUPPORTED: c++98, c++03
12
13 // <future>
14
15 // class packaged_task<R(ArgTypes...)>
16
17 // template <class R, class... ArgTypes>
18 // void
19 // swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y);
20
21 #include <future>
22 #include <cassert>
23
24 class A
25 {
26 long data_;
27
28 public:
A(long i)29 explicit A(long i) : data_(i) {}
30
operator ()(long i,long j) const31 long operator()(long i, long j) const {return data_ + i + j;}
32 };
33
main()34 int main()
35 {
36 {
37 std::packaged_task<double(int, char)> p0(A(5));
38 std::packaged_task<double(int, char)> p;
39 swap(p, p0);
40 assert(!p0.valid());
41 assert(p.valid());
42 std::future<double> f = p.get_future();
43 p(3, 'a');
44 assert(f.get() == 105.0);
45 }
46 {
47 std::packaged_task<double(int, char)> p0;
48 std::packaged_task<double(int, char)> p;
49 swap(p, p0);
50 assert(!p0.valid());
51 assert(!p.valid());
52 }
53 }
54