[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / futures / futures.task / futures.task.members / operator.pass.cpp
blobe6c833ef23a83fd4879d3316c5e092f49617a7aa
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
12 // <future>
14 // class packaged_task<R(ArgTypes...)>
16 // void operator()(ArgTypes... args);
18 #include <future>
19 #include <cassert>
21 #include "make_test_thread.h"
22 #include "test_macros.h"
24 class A
26 long data_;
28 public:
29 explicit A(long i) : data_(i) {}
31 long operator()(long i, long j) const
33 if (j == 122)
34 TEST_THROW(A(6));
35 return data_ + i + j;
39 void func0(std::packaged_task<double(int, char)> p)
41 std::this_thread::sleep_for(std::chrono::milliseconds(500));
42 p(3, 97);
45 void func1(std::packaged_task<double(int, char)> p)
47 std::this_thread::sleep_for(std::chrono::milliseconds(500));
48 p(3, 122);
51 void func2(std::packaged_task<double(int, char)> p)
53 #ifndef TEST_HAS_NO_EXCEPTIONS
54 p(3, 97);
55 try {
56 p(3, 99);
58 catch (const std::future_error& e)
60 assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
62 #else
63 ((void)p);
64 #endif
67 void func3(std::packaged_task<double(int, char)> p)
69 #ifndef TEST_HAS_NO_EXCEPTIONS
70 try
72 p(3, 97);
74 catch (const std::future_error& e)
76 assert(e.code() == make_error_code(std::future_errc::no_state));
78 #else
79 ((void)p);
80 #endif
83 int main(int, char**)
86 std::packaged_task<double(int, char)> p(A(5));
87 std::future<double> f = p.get_future();
88 support::make_test_thread(func0, std::move(p)).detach();
89 assert(f.get() == 105.0);
91 #ifndef TEST_HAS_NO_EXCEPTIONS
93 std::packaged_task<double(int, char)> p(A(5));
94 std::future<double> f = p.get_future();
95 support::make_test_thread(func1, std::move(p)).detach();
96 try
98 f.get();
99 assert(false);
101 catch (const A& e)
103 assert(e(3, 97) == 106.0);
107 std::packaged_task<double(int, char)> p(A(5));
108 std::future<double> f = p.get_future();
109 std::thread t = support::make_test_thread(func2, std::move(p));
110 assert(f.get() == 105.0);
111 t.join();
114 std::packaged_task<double(int, char)> p;
115 std::thread t = support::make_test_thread(func3, std::move(p));
116 t.join();
118 #endif
120 return 0;