mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Create src/util/drop.hpp
This commit is contained in:
parent
7bfb5ac0a4
commit
5f9268811f
1 changed files with 23 additions and 0 deletions
23
src/util/drop.hpp
Normal file
23
src/util/drop.hpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
namespace chatterino {
|
||||
|
||||
/**
|
||||
* Calls the destructor of var immediately.
|
||||
*
|
||||
* This is useful before noreturn functions to prevent leaking memory from complex types.
|
||||
*/
|
||||
template <typename T>
|
||||
inline void drop(T &var)
|
||||
{
|
||||
var.~T();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helps you avoid accidentally dropping a pointer not the object behind it.
|
||||
*/
|
||||
template <typename T>
|
||||
inline void drop(T * /*var*/)
|
||||
{
|
||||
static_assert(false, "Use delete on a pointer instead of drop().");
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
Loading…
Reference in a new issue