Jump to content
  • Advertisement
Sign in to follow this  

decltype on std::async

This topic is 2181 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



I was experimenting with some C++11. I want to create std::vectors of std::futures that come from std::async.

When using decltype(), this works for lambdas and functors, but not for regular functions:



unsigned int m()
    return 1;

class n {
    unsigned int operator()() { return 1; }

int main() {

    auto l = []() -> unsigned int { return 1; };
    std::vector < decltype( std::async(l) ) > r1;
    std::vector < decltype( std::async(n())  ) > r2;
    std::vector < decltype( std::async(m) ) > r3;                  -> this line fails to compile


    return 0;




But the line I indicated fails with the following compile errors:


Error    1    error C2780: 'std::future<result_of<enable_if<std::_Is_launch_type<_Fty>::value,_Fty>::type(_ArgTypes...)>::type> std::async(_Policy_type,_Fty &&,_ArgTypes &&...)' : expects 3 arguments - 1 provided    c:\users\jeroen\documents\visual studio 2013\projects\threading\threading\main.cpp    38
Error    2    error C2893: Failed to specialize function template 'std::future<result_of<enable_if<!std::_Is_launch_type<decay<_Ty>::type>::value,_Fty>::type(_ArgTypes...)>::type> std::async(_Fty &&,_ArgTypes &&...)'    c:\users\jeroen\documents\visual studio 2013\projects\threading\threading\main.cpp    38


Can somebody help me make sense of these errors?




Share this post

Link to post
Share on other sites

Your code compiles with GCC 4.8 and Clang 3.2. I'd say it's your compiler at a fault here.

Share this post

Link to post
Share on other sites

Hmm, strange. I am using the MSVC 2013 compiler.

I wonder what the reason is it does not compile.


Anyway, thank you for your help :)

Edited by godmodder

Share this post

Link to post
Share on other sites

I am using the MSVC 2013

MSVC 2013 only partially supports C++11, and there are some bugs in the features it does support.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!