I think a destructor with parameters is usable in sometimes.
Think about pmr. When we use pmr containers, for example, std::pmr::vector<std::pmr::string>
. In every std::pmr::string
, it will store a pointer to pmr allocator, however, the pointer is stored in the std::pmr::vector
, we don't have to store it in every std::pmr::string
. If we can pass the pointer to std::pmr::string
's destructor, we don't have to store it.
At current, we don't have any way to pass paramters to destructor. BTW, we can use offset to get parameter (this way is ugly and cannot be used in practice, if there are any better way, please let me know). Here is an example.
std::source_location
to usestd::source_location::current()
, so we can record/debug what func/file/line invoked the destructor. – Papyraceous