| 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, c++03 |
| 10 | |
| 11 | // <future> |
| 12 | |
| 13 | // class promise<R> |
| 14 | |
| 15 | // void promise::set_value_at_thread_exit(R&& r); |
| 16 | |
| 17 | #include <future> |
| 18 | #include <memory> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "make_test_thread.h" |
| 22 | #include "test_macros.h" |
| 23 | |
| 24 | void func(std::promise<std::unique_ptr<int>> p) |
| 25 | { |
| 26 | p.set_value_at_thread_exit(std::unique_ptr<int>(new int(5))); |
| 27 | } |
| 28 | |
| 29 | int main(int, char**) |
| 30 | { |
| 31 | { |
| 32 | std::promise<std::unique_ptr<int>> p; |
| 33 | std::future<std::unique_ptr<int>> f = p.get_future(); |
| 34 | support::make_test_thread(func, std::move(p)).detach(); |
| 35 | assert(*f.get() == 5); |
| 36 | } |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |