]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/thread/futures/futures.promise/get_future.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / thread / futures / futures.promise / get_future.pass.cpp
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 // UNSUPPORTED: libcpp-has-no-threads
11 // UNSUPPORTED: c++98, c++03
12
13 // <future>
14
15 // class promise<R>
16
17 // future<R> get_future();
18
19 #include <future>
20 #include <cassert>
21
22 #include "test_macros.h"
23
24 int main()
25 {
26     {
27         std::promise<double> p;
28         std::future<double> f = p.get_future();
29         p.set_value(105.5);
30         assert(f.get() == 105.5);
31     }
32 #ifndef TEST_HAS_NO_EXCEPTIONS
33     {
34         std::promise<double> p;
35         std::future<double> f = p.get_future();
36         try
37         {
38             f = p.get_future();
39             assert(false);
40         }
41         catch (const std::future_error& e)
42         {
43             assert(e.code() ==  make_error_code(std::future_errc::future_already_retrieved));
44         }
45     }
46     {
47         std::promise<double> p;
48         std::promise<double> p0 = std::move(p);
49         try
50         {
51             std::future<double> f = p.get_future();
52             assert(false);
53         }
54         catch (const std::future_error& e)
55         {
56             assert(e.code() ==  make_error_code(std::future_errc::no_state));
57         }
58     }
59 #endif
60 }