From ffe8433d55e676a02a3fc7c9691f104a93a5cc38 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 23 Feb 2026 22:44:55 -0500 Subject: [PATCH] Add operator bool() and test boolean checks --- include/rcp.h | 5 +++++ test/tests.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/include/rcp.h b/include/rcp.h index 2280b8e..e0d9bf5 100644 --- a/include/rcp.h +++ b/include/rcp.h @@ -99,6 +99,11 @@ public: { return !ptr; } + + operator bool() const + { + return ptr != nullptr; + } }; #define rcp_managed_root(classname) \ diff --git a/test/tests.cpp b/test/tests.cpp index 7e9186a..f0e348f 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -69,9 +69,18 @@ void test_dereference() assert((*mybase).y == 3); } +void test_booleans() +{ + rcp mybase = MyBase::create(2, 3); + assert(mybase); + rcp myderived; + assert(!myderived); +} + int main(int argc, char * argv[]) { test_destructors_called(); test_dereference(); + test_booleans(); return 0; }