1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Copyright (C) 2011,2014 Vicente J. Botet Escriba
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)
15 // <boost/thread/future.hpp>
19 // template <class ...Args>
20 // void promise::emplace(Args&& ... args);
22 #define BOOST_THREAD_VERSION 3
24 #include <boost/thread/future.hpp>
25 #include <boost/detail/lightweight_test.hpp>
26 #include <boost/static_assert.hpp>
42 BOOST_THREAD_MOVABLE_ONLY(A
)
44 A(BOOST_THREAD_RV_REF(A
) rhs
)
54 A
& operator=(BOOST_THREAD_RV_REF(A
) rhs
)
71 A
make(int i
, int j
) {
78 BOOST_THREAD_MOVABLE_ONLY(movable2
)
79 movable2() : value_(1){}
80 movable2(int i
) : value_(i
){}
81 movable2(int i
, int j
) : value_(i
+j
){}
83 //Move constructor and assignment
84 movable2(BOOST_RV_REF(movable2
) m
)
85 { value_
= m
.value_
; m
.value_
= 0; }
87 movable2
& operator=(BOOST_THREAD_RV_REF(movable2
) m
)
88 { value_
= m
.value_
; m
.value_
= 0; return *this; }
90 bool moved() const //Observer
93 int value() const //Observer
98 movable2
move_return_function2(int i
) {
104 #if defined BOOST_NO_CXX11_RVALUE_REFERENCES
105 BOOST_STATIC_ASSERT((boost::is_copy_constructible
<movable2
>::value
== false));
106 BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled
<movable2
>::value
== true));
107 BOOST_STATIC_ASSERT((boost::is_copy_constructible
<A
>::value
== false));
108 BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled
<A
>::value
== true));
110 #if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
116 boost::future
<T
> f
= p
.get_future();
120 T a
= f
.get(); (void)a
;
135 boost::future
<T
> f
= p
.get_future();
137 BOOST_TEST(f
.get().value
== 3);
141 p
.set_value(boost::move(j
));
144 catch (const boost::future_error
& e
)
146 BOOST_TEST(e
.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied
));
155 boost::promise
<movable2
> p
;
156 boost::future
<movable2
> f
= p
.get_future();
158 BOOST_TEST(f
.get().value_
== 3);
164 catch (const boost::future_error
& e
)
166 BOOST_TEST(e
.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied
));
176 boost::future
<A
> f
= p
.get_future();
178 BOOST_TEST(f
.get().value
== 3);
184 catch (const boost::future_error
& e
)
186 BOOST_TEST(e
.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied
));
197 boost::future
<T
> f
= p
.get_future();
199 boost::promise
<T
> p2(boost::move(p
));
200 BOOST_TEST(f
.get().value
== 3);
205 return boost::report_errors();