template <typename T>
这没有任何问题。但是对于函数可能需要的参数,我使用此模板构造:
template <typename ...Args>
所以现在我的代码看起来像这样:
template <typename T, typename ...Args>
T threadedFor(T func(Args... args), Args... args, int nThreads, unsigned int max, unsigned int min = 0) {
T result;
/* ... */
return result;
}
现在的问题是,我不知道如何在函数调用中传递Args... args
。我尝试了几种方法,例如:
threadedFor(function(1), 4, 5, 0);
或此:
threadedFor(function, 1, 4, 5, 0);
假设我的论点是1。
也很高兴知道这个结构typename ...Args
的名字,因为我在Google上找不到任何东西...
我尝试制作一个将在多个线程上运行for循环的函数。为了使该函数更好地与for循环中应使用的各种函数一起使用,我决定使用模板。 ...