Can std::async be use with template functions

前端 未结 2 1135
忘了有多久
忘了有多久 2021-01-04 09:48

Is std::async supose to work with template function? I\'ve tried to lauch std::reverse as an asynchronous task bu got compile-time error.

I\'ve tried to use simpler

2条回答
  •  无人及你
    2021-01-04 10:24

    std::reverse is not a function but a function template, you can use an specialization of that template (which is a function):

    auto result_reverse = std::async(&std::reverse, str.begin(), str.end());
    

提交回复
热议问题