So I was looking through some boost source code and came across this:
(from <boost/checked_delete.hpp>)
template<class T> inline void checked_delete(T * x)
{
// intentionally complex - simplification causes regressions
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
(void) sizeof(type_must_be_complete);
delete x;
}
Anyone happen to know why it is implemented in this way? Wouldn’t sizeof(T) (for example) already be enough?
Someone asked the same question earlier. This post written by Peter Dimov (one of the writers of
boost/checked_delete.hpp) pretty much speaks for itself: