諸事情でC++のreferenceを見ていて発見した。
If expression evaluates to a null pointer value, no destructors are called, and the deallocation function may or may not be called (it's implementation-defined), but the default deallocation functions are guaranteed to do nothing when handed a null pointer.
(until C++14)If expression evaluates to a null pointer value, no destructors are called, and the deallocation function is not called.
(since C++14)
C++14を境に微妙に動作が異なるが、null pointerをdeleteしても何も起きないようだ。
やったねif文が減らせるよ!
//現在
if(p){
delete p;
}
//これから
delete p;