diff --git a/include/rcp.h b/include/rcp.h index 257186c..3fe3a0d 100644 --- a/include/rcp.h +++ b/include/rcp.h @@ -105,6 +105,26 @@ public: return ptr != nullptr; } + bool operator==(const rcp & other) const + { + return ptr == other.ptr; + } + + bool operator!=(const rcp & other) const + { + return ptr != other.ptr; + } + + bool operator==(std::nullptr_t) const + { + return ptr == nullptr; + } + + bool operator!=(std::nullptr_t) const + { + return ptr != nullptr; + } + template static rcp create(Args&&... args) { diff --git a/test/tests.cpp b/test/tests.cpp index fe0298e..556db5f 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -68,14 +68,19 @@ void test_dereference() assert(mybase->y == 3); assert((*mybase).x == 2); assert((*mybase).y == 3); + rcp mybase2 = mybase; + assert(mybase == mybase2); + assert(!(mybase != mybase2)); } void test_booleans() { rcp mybase = MyBase::create(2, 3); assert(mybase); + assert(mybase != nullptr); rcp myderived; assert(!myderived); + assert(myderived == nullptr); } void test_create()