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