• 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 // 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 // <future>
16 
17 // class promise<R>
18 
19 // promise& operator=(promise&& rhs);
20 
21 #define BOOST_THREAD_VERSION 3
22 
23 #include <boost/thread/future.hpp>
24 #include <boost/detail/lightweight_test.hpp>
25 #if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
26 #include "../test_allocator.hpp"
27 #endif
28 
29 boost::mutex m0;
30 boost::mutex m1;
31 
main()32 int main()
33 {
34 #if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
35   BOOST_TEST(test_alloc_base::count == 0);
36   {
37     boost::promise<int> p0(boost::allocator_arg, test_allocator<int>());
38     boost::promise<int> p(boost::allocator_arg, test_allocator<int>());
39     BOOST_TEST(test_alloc_base::count == 2);
40     p = boost::move(p0);
41     BOOST_TEST(test_alloc_base::count == 1);
42     boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
43     BOOST_TEST(test_alloc_base::count == 1);
44     BOOST_TEST(f.valid());
45     try
46     {
47       f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
48       BOOST_TEST(false);
49     }
50     catch (const boost::future_error& e)
51     {
52       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
53     }
54     BOOST_TEST(test_alloc_base::count == 1);
55   }
56   BOOST_TEST(test_alloc_base::count == 0);
57 
58   {
59     boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>());
60     boost::promise<int&> p(boost::allocator_arg, test_allocator<int>());
61     BOOST_TEST(test_alloc_base::count == 2);
62     p = boost::move(p0);
63     BOOST_TEST(test_alloc_base::count == 1);
64     boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
65     BOOST_TEST(test_alloc_base::count == 1);
66     BOOST_TEST(f.valid());
67     try
68     {
69       f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
70       BOOST_TEST(false);
71     }
72     catch (const boost::future_error& e)
73     {
74       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
75     }
76     BOOST_TEST(test_alloc_base::count == 1);
77   }
78   BOOST_TEST(test_alloc_base::count == 0);
79   {
80     boost::promise<void> p0(boost::allocator_arg, test_allocator<void>());
81     boost::promise<void> p(boost::allocator_arg, test_allocator<void>());
82     BOOST_TEST(test_alloc_base::count == 2);
83     p = boost::move(p0);
84     BOOST_TEST(test_alloc_base::count == 1);
85     boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
86     BOOST_TEST(test_alloc_base::count == 1);
87     BOOST_TEST(f.valid());
88     try
89     {
90       f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
91       BOOST_TEST(false);
92     }
93     catch (const boost::future_error& e)
94     {
95       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
96     }
97     BOOST_TEST(test_alloc_base::count == 1);
98   }
99   BOOST_TEST(test_alloc_base::count == 0);
100 
101 #endif
102   {
103     boost::promise<int> p0;
104     boost::promise<int> p;
105     p = boost::move(p0);
106     boost::future<int> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
107     BOOST_TEST(f.valid());
108     try
109     {
110       f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
111       BOOST_TEST(false);
112     }
113     catch (const boost::future_error& e)
114     {
115       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
116     }
117   }
118 
119   {
120     boost::promise<int&> p0;
121     boost::promise<int&> p;
122     p = boost::move(p0);
123     boost::future<int&> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
124     BOOST_TEST(f.valid());
125     try
126     {
127       f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
128       BOOST_TEST(false);
129     }
130     catch (const boost::future_error& e)
131     {
132       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
133     }
134   }
135   {
136     boost::promise<void> p0;
137     boost::promise<void> p;
138     p = boost::move(p0);
139     boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
140     BOOST_TEST(f.valid());
141     try
142     {
143       f = BOOST_THREAD_MAKE_RV_REF(p0.get_future());
144       BOOST_TEST(false);
145     }
146     catch (const boost::future_error& e)
147     {
148       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
149     }
150   }
151 
152   return boost::report_errors();
153 
154 }
155 
156