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
12 // <future>
13
14 // class packaged_task<R(ArgTypes...)>
15
16 // template <class R, class... ArgTypes>
17 // void
18 // swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y);
19
20 #include <future>
21 #include <cassert>
22
23 class A
24 {
25 long data_;
26
27 public:
A(long i)28 explicit A(long i) : data_(i) {}
29
operator ()(long i,long j) const30 long operator()(long i, long j) const {return data_ + i + j;}
31 };
32
main()33 int main()
34 {
35 {
36 std::packaged_task<double(int, char)> p0(A(5));
37 std::packaged_task<double(int, char)> p;
38 swap(p, p0);
39 assert(!p0.valid());
40 assert(p.valid());
41 std::future<double> f = p.get_future();
42 p(3, 'a');
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 swap(p, p0);
49 assert(!p0.valid());
50 assert(!p.valid());
51 }
52 }
53