ARTICLE AD BOX
I want to use a parameter pack to enter a potentially infinite series of values into a function, and have the function output the average of these values. I have a basic idea of how to do something to this effect, but the best I can come up with is the following. It did not work until I removed "value" and simply made it a function for summing inputted numbers:
template<typename T0> auto average(const T0& first) { static const std::size_t value = 1; return first; } template<typename T0, typename ...Ts> auto average(const T0& first, const Ts&... pack) { value++; return (first + average(pack... ) / (value + 1)); } int main() { std::cout << average(1, 2, 3, 4, 5); return 0; }How do I make this output the correct value rather than return an error message?
Thank you for your time.
