История изменений
Исправление
vertexua,
(текущая версия)
:
В SO треде пишут
#include <memory>
template <typename T>
struct deleter {
char filler;
void operator()(T* ptr) {}
};
int main() {
static_assert(sizeof(int*) != sizeof(std::unique_ptr<int, deleter<int>>), "");
return 0;
}
:(
It's true that smart implementations can detect if D is empty and has a copy/move constructor that doesn't do anything (this is the case of default_delete<T>) and, in such case, avoid the overhead of copying a D. In addition, it can save memory by not adding any extra byte for D.
Но
unique_ptr's destructor must check whether the T* is null or not before calling the deleter. For defalt_delete<T> I believe, the optimizer might eliminate this test since it's OK to delete a null pointer.
Исходная версия
vertexua,
:
В SO треде пишут
#include <memory>
template <typename T>
struct deleter {
char filler;
void operator()(T* ptr) {}
};
int main() {
static_assert(sizeof(int*) != sizeof(std::unique_ptr<int, deleter<int>>), "");
return 0;
}
:(
It's true that smart implementations can detect if D is empty and has a copy/move constructor that doesn't do anything (this is the case of default_delete<T>) and, in such case, avoid the overhead of copying a D. In addition, it can save memory by not adding any extra byte for D.
unique_ptr's destructor must check whether the T* is null or not before calling the deleter. For defalt_delete<T> I believe, the optimizer might eliminate this test since it's OK to delete a null pointer.