Sorry for being vague with my question, but I just don't understand what does this function does and how. Code from here:
template<typename ... T>
auto sum (T ... t)
{
typename std::common_type<T...>::type result{}; //zero-initialization?
(void)std::initializer_list<int>{(result += t, 0)...}; //why 0 is here
return result;
}
I don't know why but this piece of code seems so odd, it don't look like C++ to me. Semantically, this function sums all the parameters in a result variable, obviously. But I completely do not understand why it was written that way. Using initializer_list here seem like a trick to trigger iteration over arguments in parameter pack but still...
Why initializer_list is explicitly was cast to void? To not take up extra memory?
And how iteration over parameter pack is going? Why not for example (void)std::initializer_list<int>{(result += t)...};
(it does not compile by the way).