|
Boost Users : |
Subject: Re: [Boost-users] problems with Boost.Thread on VS10
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2012-04-06 02:04:13
On 4/5/2012 2:32 AM, Igor R wrote:
> Can you provide a trivial example that reproduces the issue?
>
#include "boost/test/unit_test.hpp"
#include "boost/thread/future.hpp"
#include "boost/utility/result_of.hpp"
#include <functional>
struct async_func {
virtual ~async_func() { }
virtual void run() =0;
};
template <typename Ret>
class async_func_pt : public async_func {
boost::packaged_task<Ret> f;
public:
void run() override { f(); }
async_func_pt (boost::packaged_task<Ret>&& f) : f(std::move(f)) {}
~async_func_pt() { }
boost::unique_future<Ret> get_future() { return f.get_future(); }
};
void async_core (async_func* p);
template <typename F>
boost::unique_future<typename boost::result_of< F() >::type>
async (F&& f)
{
typedef typename boost::result_of< F() >::type RetType;
async_func_pt<RetType>* p= new async_func_pt<RetType> (boost::packaged_task<RetType>(f));
boost::unique_future<RetType> future_result= p->get_future();
async_core (p);
return std::move(future_result);
}
template <typename F, typename A1>
boost::unique_future<typename boost::result_of< F(A1) >::type>
async (F&& f, A1&& a1)
{
// This should be all it needs. But get a funny error deep inside Boost.
// problem overloading with && ?
return async (std::tr1::bind(f,a1));
}
BOOST_AUTO_TEST_SUITE(thread_pool_tests)
int calculate_the_answer_to_life_the_universe_and_everything()
{
return 42;
}
size_t foo (const std::string& s)
{
return s.size();
}
BOOST_AUTO_TEST_CASE( async_test )
{
// this one works
// most fundimental form:
boost::unique_future<int> fi= async
(&calculate_the_answer_to_life_the_universe_and_everything);
int i= fi.get();
BOOST_CHECK_EQUAL (i, 42);
// This one chokes at compile time
boost::unique_future<size_t> fut_1= async (&foo, "Life");
BOOST_CHECK_EQUAL (fut_1.get(), 4);
}
BOOST_AUTO_TEST_SUITE_END()
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net