Boost logo

Boost Users :

Subject: [Boost-users] Using unique_future in C++03, boost 1.47.0
From: Kelvin Chung (kelvSYC_at_[hidden])
Date: 2011-12-02 01:27:36


I have a bunch of boost::packaged_task<unsigned long>, which I intend
to execute on separate boost::threads. Before I do that, though, I
want to insert each boost::unique_future<unsigned long> in a container
as I make them. Given that I am using C++03 and boost 1.47.0 (boost
1.48.0 craps out over an ambiguous overload of boost::move), I have
something like the following:

std::deque<boost::unique_future<unsigned long>> futures;
// std::deque<boost::thread> evalThreads; TODO
for (…) {
        boost::packaged_task<unsigned long> task = …; // Create the tasks, one
at a time
        boost::unique_future<unsigned long> taskResult = task.get_future();
        // boost::thread taskThread(boost::move(task)); TODO
        
        // boost::unique_future and boost::thread can't be copied, but can be moved
        futures.push_back(boost::move(taskResult));
        // evalThreads.push_back(boost::move(taskThread)); TODO
}
boost::wait_for_all(futures.begin(), futures.end());
// Now we can do stuff with futures

The problem is that the code above is failing to compile, saying that

/usr/include/c++/4.1.2/ext/new_allocator.h:104: error: passing ‘const
boost::unique_future<long unsigned int>’ as ‘this’ argument of
‘boost::unique_future<R>::operator
boost::detail::thread_move_t<boost::unique_future<R> >() [with R = long
unsigned int]’ discards qualifiers

I don't fully understand the problem, but I blame the move emulation.
How do I fix this?


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