blob: dab4bf7e9c8321c37cc26e5891f2eb7a5f02c46d [file] [log] [blame]
Howard Hinnantf39daa82010-08-28 21:01:06 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantf39daa82010-08-28 21:01:06 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnantf39daa82010-08-28 21:01:06 +000011
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 Hinnant73d21a42010-09-04 23:28:19 +000022#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf39daa82010-08-28 21:01:06 +000023
24struct A
25{
26 A() {}
27 A(const A&) = delete;
28 A(A&&) {throw 9;}
29};
30
Howard Hinnant73d21a42010-09-04 23:28:19 +000031#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf39daa82010-08-28 21:01:06 +000032
33int main()
34{
Howard Hinnant73d21a42010-09-04 23:28:19 +000035#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf39daa82010-08-28 21:01:06 +000036 {
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 Hinnant73d21a42010-09-04 23:28:19 +000068#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf39daa82010-08-28 21:01:06 +000069}