Assuming that we have a T myarray[100] with T = int, unsigned int, long long int or unsigned long long int, what is the fastest way to reset all its content to
Here's the function I use:
template
static void setValue(T arr[], size_t length, const T& val)
{
std::fill(arr, arr + length, val);
}
template
static void setValue(T (&arr)[N], const T& val)
{
std::fill(arr, arr + N, val);
}
You can call it like this:
//fixed arrays
int a[10];
setValue(a, 0);
//dynamic arrays
int *d = new int[length];
setValue(d, length, 0);
Above is more C++11 way than using memset. Also you get compile time error if you use dynamic array with specifying the size.