I have these three helper functions that I've used on some projects as a slightly better alternative to the C memset function. The objective is to simplify and clarify code, as well as add asserts where possible:// Zero fills a POD type, such as a structure or union.template<class T>void ZeroStruct(T & s){    std::memset(&s, 0, sizeof(T));}// Zero fills a statically allocated array of POD or built-in types. Array length inferred by the compiler.template<class T, size_t N>void ZeroArray(T (&arr)[N]){    std::memset(arr, 0, sizeof(T) * N);}// Zero fills an array of POD or built-in types, with array length provided by the caller.template<class T>void ZeroArray(T * arr, size_t arrayLength){    assert(arr != nullptr);    assert(arrayLength != 0);    std::memset(arr, 0, sizeof(T) * arrayLength);}Usage example:int arr[128];ZeroArray(arr);struct S {    int   x;    float y;};S s;ZeroStruct(s);I'd like to further improve those functions with C++11/14 features. I think it would be a good idea to static_assert with std::is_pod to ensure they are never called on a class instance. Do you agree?Also, should I make them noexept?Any other recommendations?
Wrapper template functions for memset()
c++;c++11;c++14
I think it would be a good idea to static_assert with std::is_pod to ensure they are never called on a class instance. Do you agree?Making your coding easier and preventing errors with memset is the only reason I can see for your helpers. You are actually creating something like improved version of bzero (which was deprecated, but that is different story). One answer here.More than once I've come across a bug that looked like:memset(someobject, size_of_object, 0);    // clear objectThe compiler won't complain ...There are still very few cases when you need to zero the memory of a struct or an array:When you are reusing the struct/array (but which library function really needs that?)For security reasons (not to leave passwords in memory).Other cases are covered by initialization (= {0} or = the_struct()).Finally, why PascalCasing on the name? bzero or zero_fill would be better for C++ (as PascalCasing is for types, unless you are in Microsoft world).Also, should I make them noexcept?Sounds like a good idea (for first two versions, when the size is determined from the type, not provided explicitly). The third version is problematic and a bit unclear, I would completely remove it and use memset/std::fill in such cases to make your code more obvious (readable and understandable), because you already have to take care to provide proper array size - you should think twice here and rather type a bit more instead of using unclear helpers (just personal advice).