1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
14 // class packaged_task<R(ArgTypes...)>
17 // explicit packaged_task(F&& f);
22 #include "test_macros.h"
32 explicit A(long i
) : data_(i
) {}
33 A(A
&& a
) : data_(a
.data_
) {++n_moves
; a
.data_
= -1;}
34 A(const A
& a
) : data_(a
.data_
) {++n_copies
;}
36 long operator()(long i
, long j
) const {return data_
+ i
+ j
;}
42 int func(int i
) { return i
; }
47 std::packaged_task
<double(int, char)> p(A(5));
49 std::future
<double> f
= p
.get_future();
51 assert(f
.get() == 105.0);
52 assert(A::n_copies
== 0);
53 assert(A::n_moves
> 0);
59 std::packaged_task
<double(int, char)> p(a
);
61 std::future
<double> f
= p
.get_future();
63 assert(f
.get() == 105.0);
64 assert(A::n_copies
> 0);
65 assert(A::n_moves
> 0);
68 std::packaged_task
<int(int)> p(&func
);
70 std::future
<int> f
= p
.get_future();
75 std::packaged_task
<int(int)> p(func
);
77 std::future
<int> f
= p
.get_future();