I've been thinking about it recently, and the only argument I can see for having an equality operator for std::unique_ptr is for completeness so all of the smart pointers in the standard template library have it. But unless you've done something wrong, I can't see any example where it might return true
.
It's obviously possible to do something like:
int* a = new int(1);
std::unique_ptr<int> u_a1(a);
std::unique_ptr<int> u_a2(a);
if(u_a1 == u_a2)
{
std::cout << "I'm double deleting soon" << std::endl;
}
But doesn't the inclusion of the operator just allow for people to make these kind of mistakes without the compiler throwing an error? Wouldn't it make more sense to remove it, or am I missing something?
Aucun commentaire:
Enregistrer un commentaire