1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <future>
11 
12 // class promise<R>
13 
14 // future<R> get_future();
15 
16 #include <future>
17 #include <cassert>
18 
main()19 int main()
20 {
21     {
22         std::promise<double> p;
23         std::future<double> f = p.get_future();
24         p.set_value(105.5);
25         assert(f.get() == 105.5);
26     }
27     {
28         std::promise<double> p;
29         std::future<double> f = p.get_future();
30         try
31         {
32             f = p.get_future();
33             assert(false);
34         }
35         catch (const std::future_error& e)
36         {
37             assert(e.code() ==  make_error_code(std::future_errc::future_already_retrieved));
38         }
39     }
40     {
41         std::promise<double> p;
42         std::promise<double> p0 = std::move(p);
43         try
44         {
45             std::future<double> f = p.get_future();
46             assert(false);
47         }
48         catch (const std::future_error& e)
49         {
50             assert(e.code() ==  make_error_code(std::future_errc::no_state));
51         }
52     }
53 }
54