我想编写一个模板函数,像这样:平等参数类型可变参数模板功能
template <typename T>
void f(const T & ...args) // <-- This doesn't work, unfortunately.
{
std::array<T> arr = { args... };
// and so forth.
}
显然,C++不允许的,因为需要有在左侧的模板参数包这个工作的一方...args
。我想要的是一个模板函数,其中所有参数类型都是相同的。有没有简单的方法来做到这一点?
如果你知道每一个参数的类型是相同的:'模板无效F(T const的&X ,Ts const&... xs){array arr = {x,xs ...};}' –
0x499602D2
是类似的? http://stackoverflow.com/questions/30773216/variadic-template-parameters-of-one-specific-type – nonsensation