4 ms·
Writing a generic function to sum an array of any numbers type is trivial in C++. There's no 4 day research period, even if you're new to templates. templa
by dataangel 4y ago
Writing a generic function to sum an array of any numbers type is trivial in C++. There's no 4 day research period, even if you're new to templates.
template<class T>
T sum(T* x, size_t size)
{
T acc = 0;
for(size_t i = 0; i < size; ++i)
acc += x[i];
return acc;
}