any: detect C-style arrays and use delete[] when needed

This commit is contained in:
Michele Caini
2021-01-13 13:30:10 +01:00
parent 39ecd1545c
commit 505cfdd193

View File

@@ -115,7 +115,11 @@ class any {
as<any>(to).instance = from.instance;
break;
case operation::DTOR:
delete static_cast<const Type *>(from.instance);
if constexpr(std::is_array_v<Type>) {
delete[] static_cast<const Type *>(from.instance);
} else {
delete static_cast<const Type *>(from.instance);
}
break;
case operation::COMP:
return compare<Type>(from.instance, to) ? to : nullptr;