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...)>
21 #include "make_test_thread.h"
22 #include "test_macros.h"
29 explicit A(long i
) : data_(i
) {}
31 long operator()(long i
, long j
) const {return data_
+ i
+ j
;}
34 void func(std::packaged_task
<double(int, char)>)
38 void func2(std::packaged_task
<double(int, char)> p
) { p(3, 97); }
42 #ifndef TEST_HAS_NO_EXCEPTIONS
44 std::packaged_task
<double(int, char)> p(A(5));
45 std::future
<double> f
= p
.get_future();
46 support::make_test_thread(func
, std::move(p
)).detach();
50 ((void)i
); // Prevent unused warning
53 catch (const std::future_error
& e
)
55 assert(e
.code() == make_error_code(std::future_errc::broken_promise
));
60 std::packaged_task
<double(int, char)> p(A(5));
61 std::future
<double> f
= p
.get_future();
62 support::make_test_thread(func2
, std::move(p
)).detach();
63 assert(f
.get() == 105.0);