需要異步運行一個函數,當函數採用模板參數。下面的代碼不能編譯,有幫助嗎?呼叫模板功能與異步
template<typename T>
void say(int n, T t) {
cout << " say: " << n << " " << t << endl;
}
template<typename F, typename... Ts>
inline auto reallyAsync(F&& f, Ts&&... params){
return std::async(
std::launch::async,
std::forward<F>(f),
std::forward<Ts>(params)...);
}
int main() {
int n = 10; float x = 100;
say(n, x); // works
reallyAsync(&say, n, x) ; // does not work
}
這將有助於增加編譯器會引發出用於 – Stormenet
@Stormenet或編譯器錯誤。 –