template<class� T>
auto func(const T&� t){
std::initializer_list<?> ilist = {t�}; //what should go here <?>//
for(const auto& arg : ilist)
//use arg//
}
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Another two solutions (samples):
// if you expect only integers
template<int... Nums>
int make_sum()
{
auto list = {Nums...};
int result = 0;
return std::accumulate(list.begin(), list.end(), result);
}
// If you expect variadic params list of any type compatible each
other. For example, numeric types.
template<typename... Nums>
double make_sum(Nums ... nums)
{
auto list = {(double)nums...};
double result = 0;
return std::accumulate(list.begin(), list.end(), result);
}
with following usage:
std::cout << make_sum<1, 2, 3, 4, 5, 6>() << std::endl; // first case
std::cout << make_sum(1, 2, 3, 4.234, 5, 6, 7.435, 8, 9, 10) <<
std::endl; // second case
---
Best regards,
Sergey
What would be the inferred type of "list" in this example?
----------
Best regards,
Sergey