blob: a7d084ee78730d3bb744524ae6a7fb8f16e37d3a [file] [log] [blame]
Howard Hinnant54da3382010-08-30 18:46:21 +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 Hinnant54da3382010-08-30 18:46:21 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant54da3382010-08-30 18:46:21 +000011
12// <future>
13
14// class promise<R>
15
16// future<R> get_future();
17
18#include <future>
19#include <cassert>
20
21int main()
22{
23 {
24 std::promise<double> p;
25 std::future<double> f = p.get_future();
26 p.set_value(105.5);
27 assert(f.get() == 105.5);
28 }
29 {
30 std::promise<double> p;
31 std::future<double> f = p.get_future();
32 try
33 {
34 f = p.get_future();
35 assert(false);
36 }
37 catch (const std::future_error& e)
38 {
39 assert(e.code() == make_error_code(std::future_errc::future_already_retrieved));
40 }
41 }
42 {
43 std::promise<double> p;
44 std::promise<double> p0 = std::move(p);
45 try
46 {
47 std::future<double> f = p.get_future();
48 assert(false);
49 }
50 catch (const std::future_error& e)
51 {
52 assert(e.code() == make_error_code(std::future_errc::no_state));
53 }
54 }
55}