• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // void promise<R&>::set_value(R& r);
18 
19 #include <future>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 
main()24 int main()
25 {
26     {
27         typedef int& T;
28         int i = 3;
29         std::promise<T> p;
30         std::future<T> f = p.get_future();
31         p.set_value(i);
32         int& j = f.get();
33         assert(j == 3);
34         ++i;
35         assert(j == 4);
36 #ifndef TEST_HAS_NO_EXCEPTIONS
37         try
38         {
39             p.set_value(i);
40             assert(false);
41         }
42         catch (const std::future_error& e)
43         {
44             assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
45         }
46 #endif
47     }
48 }
49