blob: 61a66ad407ceca818ae19b28aee7ddb1a341014e [file] [log] [blame]
Howard Hinnantf39daa82010-08-28 21:01:06 +00001//===----------------------------------------------------------------------===//
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 Hinnant73d21a42010-09-04 23:28:19 +000020#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf39daa82010-08-28 21:01:06 +000021
22struct A
23{
24 A() {}
25 A(const A&) = delete;
26 A(A&&) {throw 9;}
27};
28
Howard Hinnant73d21a42010-09-04 23:28:19 +000029#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf39daa82010-08-28 21:01:06 +000030
31int main()
32{
Howard Hinnant73d21a42010-09-04 23:28:19 +000033#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf39daa82010-08-28 21:01:06 +000034 {
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 Hinnant73d21a42010-09-04 23:28:19 +000066#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf39daa82010-08-28 21:01:06 +000067}