Oftentimes data structures\' valid initialization is to set all members to zero. Even when programming in C++, one may need to interface with an external API for which this
I found a good solution to be:
template void my_zero(T& e) {
static T dummy_zero_object;
e = dummy_zero_object;
}
my_zero(s);
This does the right thing not only for fundamental types and user-defined types, but it also zero-initializes types for which the default constructor is defined but does not initialize all member variables --- especially classes containing non-trivial union members.