Предполагается ли, чтоstd::async
работает с функцией шаблона? Я пытался запуститьstd::reverse
как асинхронную задачу, но получил ошибку времени компиляции.
Я пытался использовать более простые функции (foo и bar) и обнаружил, что работают только функции, не являющиеся шаблонами.
#include
#include
#include
void foo(std::string::iterator first, std::string::iterator last)
{
}
template
void bar(BidirectionalIterator first, BidirectionalIterator last)
{
}
int main()
{
std::string str = "Lorem ipsum, dolor sit amet";
auto result_reverse = std::async(std::reverse, str.begin(), str.end()); // Compile-time error
auto result_foo = std::async(foo, str.begin(), str.end());
auto result_bar = std::async(bar, str.begin(), str.end()); // Compile-time error
result_reverse.get();
result_foo.get();
result_bar.get();
}
Ошибка компилятора выглядит следующим образом:
main.cpp: In function ‘int main()’:
main.cpp:18:71: erreur: no matching function for call to ‘async(, std::basic_string::iterator, std::basic_string::iterator)’
main.cpp:18:71: note: candidates are:
/usr/include/c++/4.6/future:1355:5: note: template std::future::type> std::async(std::launch, _Fn&&, _Args&& ...)
/usr/include/c++/4.6/future:1378:5: note: template typename std::__async_sfinae_helper::type, _Fn, _Args ...>::type std::async(_Fn&&, _Args&& ...)
main.cpp:18:71: erreur: unable to deduce ‘auto’ from ‘’
main.cpp:20:62: erreur: no matching function for call to ‘async(, std::basic_string::iterator, std::basic_string::iterator)’
main.cpp:20:62: note: candidates are:
/usr/include/c++/4.6/future:1355:5: note: template std::future::type> std::async(std::launch, _Fn&&, _Args&& ...)
/usr/include/c++/4.6/future:1378:5: note: template typename std::__async_sfinae_helper::type, _Fn, _Args ...>::type std::async(_Fn&&, _Args&& ...)
main.cpp:20:62: erreur: unable to deduce ‘auto’ from ‘’
Однако она проходит, когда я вручную указываю экземпляр шаблона, например std::async(std::reverse<:string::iterator>, str .begin(), str.end())
.
Является ли это ошибкой компилятора (GCC 4.6.3) или четко определенным поведением?