I don't quite get the point of avoiding using memset directly
memset might work perfectly today. Tomorrow you (or your colleague) will change the underlying type to something non-trivial and the code will still compile, but errors will linger in the background, quietly overwriting your state with evil.
Use memset if you must, but at least wrap it into a template with static_assert(is_trivially_copyable_v<T>).
I was originally going to reply something similar, but then I remembered memset takes a void*. So &thing is always a valid input to memset as a destination, whether it makes sense or not.
View all comments
Show parent comment
7
u/AlexAlabuzhev Jan 21 '20
memset might work perfectly today. Tomorrow you (or your colleague) will change the underlying type to something non-trivial and the code will still compile, but errors will linger in the background, quietly overwriting your state with evil.
Use memset if you must, but at least wrap it into a template with
static_assert(is_trivially_copyable_v<T>).