1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:37:35 +00:00

Add WeakPtr/Weakable templates.

This commit is contained in:
Andreas Kling 2018-10-13 15:41:24 +02:00
parent b7efd92937
commit 3e9a45d7f4
4 changed files with 109 additions and 2 deletions

View file

@ -7,6 +7,10 @@
#include "HashMap.h"
#include "TemporaryFile.h"
#include "Buffer.h"
#include "Weakable.h"
#include "WeakPtr.h"
static void testWeakPtr();
int main(int, char**)
{
@ -183,5 +187,27 @@ int main(int, char**)
printInts(h);
}
testWeakPtr();
return 0;
}
class TestWeakable : public Weakable<TestWeakable> {
public:
TestWeakable() { }
~TestWeakable() { }
};
void testWeakPtr()
{
auto* weakable = new TestWeakable;
auto weakPtr = weakable->makeWeakPtr();
ASSERT(weakPtr);
ASSERT(weakPtr.ptr() == weakable);
delete weakable;
ASSERT(!weakPtr);
ASSERT(weakPtr.ptr() == nullptr);
}