Add a make_rcp<>() helper method
Saves us from having to type the class name twice:
make_rcp<MyClass>()
vs.
rcp<MyClass>(new MyClass())
Diffs=
51eb2ee20 Add a make_rcp<>() helper method
diff --git a/.rive_head b/.rive_head
index 0d39faa..73ef988 100644
--- a/.rive_head
+++ b/.rive_head
@@ -1 +1 @@
-2ad434e801bb43922a15c4313df3bf6c0c9efcf8
+51eb2ee206984a0496ece3f44b5e24ec38827b7c
diff --git a/include/rive/refcnt.hpp b/include/rive/refcnt.hpp
index e4b1509..d11104c 100644
--- a/include/rive/refcnt.hpp
+++ b/include/rive/refcnt.hpp
@@ -143,6 +143,10 @@
template <typename T> inline void swap(rcp<T>& a, rcp<T>& b) { a.swap(b); }
+template <typename T, typename... Args> rcp<T> inline make_rcp(Args&&... args) {
+ return rcp<T>(new T(std::forward<Args>(args)...));
+}
+
// == variants
template <typename T> inline bool operator==(const rcp<T>& a, std::nullptr_t) { return !a; }
diff --git a/test/refcnt_test.cpp b/test/refcnt_test.cpp
index 676617a..211825a 100644
--- a/test/refcnt_test.cpp
+++ b/test/refcnt_test.cpp
@@ -11,6 +11,7 @@
class MyRefCnt : public RefCnt<MyRefCnt> {
public:
MyRefCnt() {}
+ MyRefCnt(int, float, bool) {}
void require_count(int value) { REQUIRE(this->debugging_refcnt() == value); }
};
@@ -39,7 +40,7 @@
REQUIRE(r0.get() == nullptr);
REQUIRE(!r0);
- rcp<MyRefCnt> r1(new MyRefCnt);
+ auto r1 = make_rcp<MyRefCnt>();
REQUIRE(r1.get() != nullptr);
REQUIRE(r1);
REQUIRE(r1 != r0);
@@ -50,6 +51,12 @@
REQUIRE(r1 == r2);
REQUIRE(r2->debugging_refcnt() == 2);
+ auto r3 = make_rcp<MyRefCnt>(1, .5f, false);
+ REQUIRE(r3.get() != nullptr);
+ REQUIRE(r3);
+ REQUIRE(r3 != r1);
+ REQUIRE(r3->debugging_refcnt() == 1);
+
auto ptr = r2.release();
REQUIRE(r2.get() == nullptr);
REQUIRE(r1.get() == ptr);