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,2014 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 // future<void> make_ready_future();
20 // template <class T>
21 // future<decay_t<T>> make_ready_future(T&&);
22 // template <class T>
23 // future<T> make_ready_future(remove_reference_t<T>&);
24 // template <class T>
25 // future<T> make_ready_future(remove_reference_t<T>&&);
26 // template <class T, class ...Args>
27 // future<T> make_ready_future(Args&& ... args);
28
29 #define BOOST_THREAD_VERSION 3
30
31 #include <boost/thread/future.hpp>
32 #include <boost/detail/lightweight_test.hpp>
33 #include <boost/static_assert.hpp>
34
35 struct A
36 {
AA37 A() :
38 value(0)
39 {
40 }
AA41 A(int i) :
42 value(i)
43 {
44 }
AA45 A(int i, int j) :
46 value(i+j)
47 {
48 }
49 int value;
50 };
51
make(int i)52 A make(int i) {
53 return A(i);
54 }
make(int i,int j)55 A make(int i, int j) {
56 return A(i, j);
57 }
58
59 struct movable2
60 {
61 int value_;
62 BOOST_THREAD_MOVABLE_ONLY(movable2)
movable2movable263 movable2() : value_(1){}
movable2movable264 movable2(int i) : value_(i){}
movable2movable265 movable2(int i, int j) : value_(i+j){}
66
67 //Move constructor and assignment
movable2movable268 movable2(BOOST_RV_REF(movable2) m)
69 { value_ = m.value_; m.value_ = 0; }
70
operator =movable271 movable2 & operator=(BOOST_THREAD_RV_REF(movable2) m)
72 { value_ = m.value_; m.value_ = 0; return *this; }
73
movedmovable274 bool moved() const //Observer
75 { return !value_; }
76
valuemovable277 int value() const //Observer
78 { return value_; }
79 };
80
81
move_return_function2(int i)82 movable2 move_return_function2(int i) {
83 return movable2(i);
84 }
85
main()86 int main()
87 {
88 #if defined BOOST_NO_CXX11_RVALUE_REFERENCES
89 BOOST_STATIC_ASSERT((boost::is_copy_constructible<movable2>::value == false));
90 BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled<movable2>::value == true));
91 BOOST_STATIC_ASSERT((boost::is_copy_constructible<A>::value == true));
92 BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled<A>::value == false));
93 #endif
94
95 {
96 boost::future<void> f = boost::make_ready_future();
97 f.wait();
98 }
99 {
100 typedef A T;
101 T i;
102 boost::future<T> f = boost::make_ready_future(i);
103 BOOST_TEST(f.get().value==0);
104 }
105 #if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
106 {
107 typedef A T;
108 boost::future<T> f = boost::make_ready_future<T>();
109 BOOST_TEST(f.get().value==0);
110 }
111 {
112 typedef A T;
113 boost::future<T> f = boost::make_ready_future<T>(1);
114 BOOST_TEST(f.get().value==1);
115 }
116 {
117 typedef A T;
118 boost::future<T> f = boost::make_ready_future<T>(1,2);
119 BOOST_TEST(f.get().value==3);
120 }
121 {
122 typedef A T;
123 T i;
124 boost::future<T&> f = boost::make_ready_future<T&>(i);
125 BOOST_TEST(f.get().value==0);
126 }
127 #endif
128 #if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
129 // sync/futures/make_ready_future_pass.cpp:125:65: erreur: conversion from �boost::future<boost::rv<movable2> >� to non-scalar type �boost::future<movable2>� requested
130 {
131 typedef movable2 T;
132 T i;
133 boost::future<T> f = boost::make_ready_future(boost::move(i));
134 BOOST_TEST_EQ(f.get().value(),1);
135 }
136 #endif
137 #if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
138 {
139 typedef movable2 T;
140 boost::future<T> f = boost::make_ready_future<T>();
141 BOOST_TEST(f.get().value()==1);
142 }
143 {
144 typedef movable2 T;
145 boost::future<T> f = boost::make_ready_future<T>(1);
146 BOOST_TEST(f.get().value()==1);
147 }
148 {
149 typedef movable2 T;
150 boost::future<T> f = boost::make_ready_future<T>(1,2);
151 BOOST_TEST(f.get().value()==3);
152 }
153 #endif
154
155 return boost::report_errors();
156 }
157
158