1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011,2014 Vicente J. Botet Escriba
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// <boost/thread/future.hpp>
// class promise<R>
// future<void> make_ready_future();
// template <class T>
// future<decay_t<T>> make_ready_future(T&&);
// template <class T>
// future<T> make_ready_future(remove_reference_t<T>&);
// template <class T>
// future<T> make_ready_future(remove_reference_t<T>&&);
// template <class T, class ...Args>
// future<T> make_ready_future(Args&& ... args);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
struct A
{
A() :
value(0)
{
}
A(int i) :
value(i)
{
}
A(int i, int j) :
value(i+j)
{
}
int value;
};
A make(int i) {
return A(i);
}
A make(int i, int j) {
return A(i, j);
}
struct movable2
{
int value_;
BOOST_THREAD_MOVABLE_ONLY(movable2)
movable2() : value_(1){}
movable2(int i) : value_(i){}
movable2(int i, int j) : value_(i+j){}
//Move constructor and assignment
movable2(BOOST_RV_REF(movable2) m)
{ value_ = m.value_; m.value_ = 0; }
movable2 & operator=(BOOST_THREAD_RV_REF(movable2) m)
{ value_ = m.value_; m.value_ = 0; return *this; }
bool moved() const //Observer
{ return !value_; }
int value() const //Observer
{ return value_; }
};
movable2 move_return_function2(int i) {
return movable2(i);
}
int main()
{
#if defined BOOST_NO_CXX11_RVALUE_REFERENCES
BOOST_STATIC_ASSERT((boost::is_copy_constructible<movable2>::value == false));
BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled<movable2>::value == true));
BOOST_STATIC_ASSERT((boost::is_copy_constructible<A>::value == true));
BOOST_STATIC_ASSERT((boost::has_move_emulation_enabled<A>::value == false));
#endif
{
boost::future<void> f = boost::make_ready_future();
f.wait();
}
{
typedef A T;
T i;
boost::future<T> f = boost::make_ready_future(i);
BOOST_TEST(f.get().value==0);
}
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
{
typedef A T;
boost::future<T> f = boost::make_ready_future<T>();
BOOST_TEST(f.get().value==0);
}
{
typedef A T;
boost::future<T> f = boost::make_ready_future<T>(1);
BOOST_TEST(f.get().value==1);
}
{
typedef A T;
boost::future<T> f = boost::make_ready_future<T>(1,2);
BOOST_TEST(f.get().value==3);
}
{
typedef A T;
T i;
boost::future<T&> f = boost::make_ready_future<T&>(i);
BOOST_TEST(f.get().value==0);
}
#endif
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
// 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
{
typedef movable2 T;
T i;
boost::future<T> f = boost::make_ready_future(boost::move(i));
BOOST_TEST_EQ(f.get().value(),1);
}
#endif
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
{
typedef movable2 T;
boost::future<T> f = boost::make_ready_future<T>();
BOOST_TEST(f.get().value()==1);
}
{
typedef movable2 T;
boost::future<T> f = boost::make_ready_future<T>(1);
BOOST_TEST(f.get().value()==1);
}
{
typedef movable2 T;
boost::future<T> f = boost::make_ready_future<T>(1,2);
BOOST_TEST(f.get().value()==3);
}
#endif
return boost::report_errors();
}
|