Opened 12 years ago

Closed 10 years ago

#4710 closed Feature Requests (fixed)

c++11 compliance: : Missing async()

Reported by: Dave Abrahams Owned by: viboes
Milestone: Boost 1.52.0 Component: thread
Version: Boost 1.44.0 Severity: Problem
Keywords: async standard Cc: viboes

Description

The lack of an async() call makes futures awfully cumbersome to use. I hacked up this nullary prototype for C++03. It's better than nothing!

#include <boost/thread.hpp>
#include <boost/utility/result_of.hpp>

template <class F>
boost::detail::thread_move_t<boost::unique_future<typename boost::result_of<F()>::type> >
async(F f)
{
    typedef typename boost::result_of<F()>::type R;
    boost::packaged_task<R> pt( f );
    
    typedef boost::unique_future<R> future;
    future ret = pt.get_future();
    boost::thread( boost::move(pt) ).detach();
    return boost::move(ret);
}

Change History (9)

comment:1 by viboes, 12 years ago

Component: threadsthread
Type: BugsFeature Requests

comment:2 by viboes, 11 years ago

Cc: viboes added
Keywords: async standard added

comment:3 by anonymous, 11 years ago

Summary: Missing async()c++11 complicance: : Missing async()

comment:4 by viboes, 11 years ago

Summary: c++11 complicance: : Missing async()c++11 compliance: : Missing async()

comment:5 by viboes, 11 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:6 by viboes, 10 years ago

Milestone: To Be DeterminedBoost 1.52.0

comment:7 by viboes, 10 years ago

Add

template <class F, class... Args>
  future<typename result_of<F(Args...)>::type>
  async(F&& f, Args&&... args);
template <class F, class... Args>
  future<typename result_of<F(Args...)>::type>
  async(launch policy, F&& f, Args&&... args);

to conform with c++11.

in reply to:  7 comment:8 by viboes, 10 years ago

Replying to viboes:

Add

template <class F, class... Args>
  future<typename result_of<F(Args...)>::type>
  async(F&& f, Args&&... args);
template <class F, class... Args>
  future<typename result_of<F(Args...)>::type>
  async(launch policy, F&& f, Args&&... args);

to conform with c++11.

I will implement these prototypes later on.

For the time been, the minimal request has benn done.

comment:9 by viboes, 10 years ago

Resolution: fixed
Status: assignedclosed

Merged from trunk [80450].

Note: See TracTickets for help on using tickets.