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