Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jonathan Roelofs | 8d86b2e | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 9 | // |
| 10 | // UNSUPPORTED: libcpp-has-no-threads |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 11 | |
| 12 | // <future> |
| 13 | |
| 14 | // class promise<R> |
| 15 | |
| 16 | // void promise::set_value(R&& r); |
| 17 | |
| 18 | #include <future> |
| 19 | #include <memory> |
| 20 | #include <cassert> |
| 21 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 22 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 23 | |
| 24 | struct A |
| 25 | { |
| 26 | A() {} |
| 27 | A(const A&) = delete; |
| 28 | A(A&&) {throw 9;} |
| 29 | }; |
| 30 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 31 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 32 | |
| 33 | int main() |
| 34 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 35 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 36 | { |
| 37 | typedef std::unique_ptr<int> T; |
| 38 | T i(new int(3)); |
| 39 | std::promise<T> p; |
| 40 | std::future<T> f = p.get_future(); |
| 41 | p.set_value(std::move(i)); |
| 42 | assert(*f.get() == 3); |
| 43 | try |
| 44 | { |
| 45 | p.set_value(std::move(i)); |
| 46 | assert(false); |
| 47 | } |
| 48 | catch (const std::future_error& e) |
| 49 | { |
| 50 | assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied)); |
| 51 | } |
| 52 | } |
| 53 | { |
| 54 | typedef A T; |
| 55 | T i; |
| 56 | std::promise<T> p; |
| 57 | std::future<T> f = p.get_future(); |
| 58 | try |
| 59 | { |
| 60 | p.set_value(std::move(i)); |
| 61 | assert(false); |
| 62 | } |
| 63 | catch (int j) |
| 64 | { |
| 65 | assert(j == 9); |
| 66 | } |
| 67 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 68 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 69 | } |