diff --git a/include/rcp.h b/include/rcp.h index b439666..eaacf74 100644 --- a/include/rcp.h +++ b/include/rcp.h @@ -123,16 +123,14 @@ public: } }; -template -class managed -{ -public: - static_assert(std::is_base_of::value, - "T must inherit from rcp::root to use rcp::managed"); - - rcp get_rcp() - { - root * r = (root *)this; - return rcp(r->get_root_rcp()); +#define rcp_managed(classname) \ + rcp get_rcp() \ + { \ + root * r = (root *)this; \ + return rcp(r->get_root_rcp()); \ + } \ + template \ + static rcp create(Args&&... args) \ + { \ + return (new classname(std::forward(args)...))->get_rcp(); \ } -}; diff --git a/test/tests.cpp b/test/tests.cpp index 519a476..04645bc 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -1,5 +1,23 @@ #include +class MyBase : public root +{ +protected: + MyBase(int x, int y) {} + +public: + rcp_managed(MyBase); +}; + +class MyDerived : public MyBase +{ +protected: + MyDerived(double v) : MyBase(1, 2) {} + +public: + rcp_managed(MyDerived) +}; + int main(int argc, char * argv[]) { return 0;