Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

std::async return type

0 views
Skip to first unread message

SG

unread,
Nov 15, 2009, 8:08:36 PM11/15/09
to
N2996 declares std::async as:

enum class launch { any, async, sync };

template<class F, class ...Args>
unique_future<typename F::result_type>
async( F&& f, Args&&... args );

template<class F, class ...Args>
unique_future<typename F::result_type>
async( launch policy, F&& f, Args&&... args );

and I'm wondering why "typename F::result_type" is used instead of
"typename result_of<F(Args...)>::type" or "typename result_of<F&
(Args...)>::type". It seems we have to wrap function pointers into a
class-type object just to be able to use them for std::async. Is this
intentional or an oversight?

Cheers,
SG

--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

Daniel Krügler

unread,
Nov 16, 2009, 2:38:46 PM11/16/09
to
On Nov 16, 2:08 am, SG <s.gesem...@gmail.com> wrote:
> N2996 declares std::async as:
>
> enum class launch { any, async, sync };
>
> template<class F, class ...Args>
> unique_future<typename F::result_type>
> async( F&& f, Args&&... args );
>
> template<class F, class ...Args>
> unique_future<typename F::result_type>
> async( launch policy, F&& f, Args&&... args );
>
> and I'm wondering why "typename F::result_type" is used instead of
> "typename result_of<F(Args...)>::type" or "typename result_of<F&
> (Args...)>::type". It seems we have to wrap function pointers into a
> class-type object just to be able to use them for std::async. Is this
> intentional or an oversight?

This is an oversight, the correct one is typename result_of<F(Args...)
>::type.

Greetings from Bremen,

- Daniel Kr�gler

Anthony Williams

unread,
Nov 16, 2009, 2:39:28 PM11/16/09
to
SG <s.ges...@gmail.com> writes:

> N2996 declares std::async as:
>
> enum class launch { any, async, sync };
>
> template<class F, class ...Args>
> unique_future<typename F::result_type>
> async( F&& f, Args&&... args );
>
> template<class F, class ...Args>
> unique_future<typename F::result_type>
> async( launch policy, F&& f, Args&&... args );
>
> and I'm wondering why "typename F::result_type" is used instead of
> "typename result_of<F(Args...)>::type" or "typename result_of<F&
> (Args...)>::type". It seems we have to wrap function pointers into a
> class-type object just to be able to use them for std::async. Is this
> intentional or an oversight?

It's an oversight. It was spotted too late for the latest WP draft.

Anthony
--
Author of C++ Concurrency in Action | http://www.manning.com/williams
just::thread C++0x thread library | http://www.stdthread.co.uk
Just Software Solutions Ltd | http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

0 new messages