C ++, Linux: error: conversion from 'boost :: unique_future <void> to the non-scalar type' boost :: shared_future <void>. how to get around this?

I am trying to work with raising futures futures . So, as shown here , we can get a shared future out of a packaged task .

So, I try such a function in linux:

template <class task_return_t>
void pool_item( boost::shared_ptr< boost::packaged_task<task_return_t> > pt)
{
    boost::shared_future<task_return_t> fi= pt->get_future(); // error
    //...

but I get an error:

../../src/cf-util/thread_pool.h: In member function ‘void thread_pool::pool_item(boost::shared_ptr<boost::packaged_task<R> >) [with task_return_t = void]’:
../../src/cf-util/thread_pool.h:64:3:   instantiated from ‘void thread_pool::post(boost::shared_ptr<boost::packaged_task<R> >) [with task_return_t = void]’
../../src/cf-server/server.cpp:39:27:   instantiated from here
../../src/cf-util/thread_pool.h:124:58: error: conversion from ‘boost::unique_future<void>’ to non-scalar type ‘boost::shared_future<void>’ requested

I have not done any futures with this task before. all the source code , the place I'm calling from , my thread pool, which is called . And on Windows, under Visual Studio 2010, it compiles and works fine.

What should I do? How to fix or get around this error?

+5
4

unique_future shared_future :

shared_future(unique_future<R> && other);

rvalue, , , "", . , V++ 2010 rvalue, , , linux (, gcc), , -std=gnu++0x. " ", ( ) , :

boost::shared_future<task_return_t> fi = boost::move(pt->get_future());
+4

. g++ (4.6.3) Linux -std = gnu ++ 0x -std = ++ 0x, ISO. -std- gnu ++ 11 ++ 11 . ( , )

+1

Is it possible that you forgot to include the correct headers?

If not, does another constructor like the one below work?

boost::shared_future<task_return_t> fi(pt->get_future());
0
source

In C ++ 11, you have to call std :: future :: share () to get shared_future from the future. For instance.

auto sf=std::async([]{/* something */}).share();
0
source

All Articles