During Andrei Alexandrescu's talk on error handling:
See C++ and Beyond 2012: Andrei Alexandrescu - Systematic Error Handling in C++ (about 30 minutes in)
Andrei presents the following piece of code:
~Expected()
{
using std::exception_ptr;
if (gotHam) ham.~T();
else spam.~exception_ptr();
}
This destructor is cleaning up a union which contains either some type T or a std::exception_ptr. The union is populated using placement new.
Andrei then explains that the using std::exception_ptr; is necessary because the following code does not parse:
else spam.~std::exception_ptr();
This means that it is always necessary to have a using directive if you need to explicitly call the destructor of a class in a different namespace.
Why doesn't the second example parse?
Would the followng code be a valid alternative?
else delete spam;
Does this have the same affect as explicitly calling the destructor of std::exception_ptr