]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/sync/futures/promise/set_value_const_pass.cpp
e549eb6e012210804e3292be9fb22b3200818d4f
[ceph.git] / ceph / src / boost / libs / thread / test / sync / futures / promise / set_value_const_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 // Copyright (C) 2011 Vicente J. Botet Escriba
11 //
12 // Distributed under the Boost Software License, Version 1.0. (See accompanying
13 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
14
15 // <boost/thread/future.hpp>
16
17 // class promise<R>
18
19 // void promise::set_value(const R& r);
20
21 #define BOOST_THREAD_VERSION 3
22
23 #include <boost/thread/future.hpp>
24 #include <boost/detail/lightweight_test.hpp>
25 #include <boost/static_assert.hpp>
26
27 struct A
28 {
29 A()
30 {
31 }
32 A(const A&)
33 {
34 throw 10;
35 }
36 };
37
38 int main()
39 {
40
41 {
42 typedef int T;
43 T i = 3;
44 boost::promise<T> p;
45 boost::future<T> f = p.get_future();
46 p.set_value(i);
47 ++i;
48 BOOST_TEST(f.get() == 3);
49 --i;
50 try
51 {
52 p.set_value(i);
53 BOOST_TEST(false);
54 }
55 catch (const boost::future_error& e)
56 {
57 BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
58 }
59 catch (...)
60 {
61 BOOST_TEST(false);
62 }
63 }
64 {
65 typedef A T;
66 T i;
67 boost::promise<T> p;
68 boost::future<T> f = p.get_future();
69 try
70 {
71 p.set_value(i);
72 BOOST_TEST(false);
73 }
74 catch (int j)
75 {
76 BOOST_TEST(j == 10);
77 }
78 catch (...)
79 {
80 BOOST_TEST(false);
81 }
82 }
83
84 return boost::report_errors();
85 }
86