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