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