1eb5cfb02SEric Fiselier //===----------------------------------------------------------------------===//
2eb5cfb02SEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6eb5cfb02SEric Fiselier //
7eb5cfb02SEric Fiselier //===----------------------------------------------------------------------===//
8eb5cfb02SEric Fiselier //
9*a7f9895cSLouis Dionne // UNSUPPORTED: no-threads
1031cbe0f2SLouis Dionne // UNSUPPORTED: c++03
11eb5cfb02SEric Fiselier
12eb5cfb02SEric Fiselier // <future>
13eb5cfb02SEric Fiselier
14eb5cfb02SEric Fiselier // class packaged_task<R(ArgTypes...)>
15eb5cfb02SEric Fiselier
16eb5cfb02SEric Fiselier // template <class R, class... ArgTypes>
17eb5cfb02SEric Fiselier // void
18eb5cfb02SEric Fiselier // swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y);
19eb5cfb02SEric Fiselier
20eb5cfb02SEric Fiselier #include <future>
21eb5cfb02SEric Fiselier #include <cassert>
22eb5cfb02SEric Fiselier
237fc6a556SMarshall Clow #include "test_macros.h"
247fc6a556SMarshall Clow
25eb5cfb02SEric Fiselier class A
26eb5cfb02SEric Fiselier {
27eb5cfb02SEric Fiselier long data_;
28eb5cfb02SEric Fiselier
29eb5cfb02SEric Fiselier public:
A(long i)30eb5cfb02SEric Fiselier explicit A(long i) : data_(i) {}
31eb5cfb02SEric Fiselier
operator ()(long i,long j) const32eb5cfb02SEric Fiselier long operator()(long i, long j) const {return data_ + i + j;}
33eb5cfb02SEric Fiselier };
34eb5cfb02SEric Fiselier
main(int,char **)352df59c50SJF Bastien int main(int, char**)
36eb5cfb02SEric Fiselier {
37eb5cfb02SEric Fiselier {
38eb5cfb02SEric Fiselier std::packaged_task<double(int, char)> p0(A(5));
39eb5cfb02SEric Fiselier std::packaged_task<double(int, char)> p;
40eb5cfb02SEric Fiselier swap(p, p0);
41eb5cfb02SEric Fiselier assert(!p0.valid());
42eb5cfb02SEric Fiselier assert(p.valid());
43eb5cfb02SEric Fiselier std::future<double> f = p.get_future();
443f05377dSMuiez Ahmed p(3, 97);
45eb5cfb02SEric Fiselier assert(f.get() == 105.0);
46eb5cfb02SEric Fiselier }
47eb5cfb02SEric Fiselier {
48eb5cfb02SEric Fiselier std::packaged_task<double(int, char)> p0;
49eb5cfb02SEric Fiselier std::packaged_task<double(int, char)> p;
50eb5cfb02SEric Fiselier swap(p, p0);
51eb5cfb02SEric Fiselier assert(!p0.valid());
52eb5cfb02SEric Fiselier assert(!p.valid());
53eb5cfb02SEric Fiselier }
542df59c50SJF Bastien
552df59c50SJF Bastien return 0;
56eb5cfb02SEric Fiselier }
57