diff --git a/research/try.cpp b/research/try.cpp index 3fd2439b2..89a9c7d3e 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -80,6 +80,7 @@ typedef unsigned int uint; #include using lib::P; +using lib::newP; using lib::diff::GenNode; using lib::meta::is_basically; using lib::meta::is_StringLike; @@ -103,14 +104,6 @@ class Reticent }; -template -inline P -newP (ARGS&&... ctorArgs) -{ - return P{new X {std::forward(ctorArgs)...}}; -} - - template using BasicallyString = is_basically; diff --git a/src/lib/p.hpp b/src/lib/p.hpp index 01d5c69c6..ef757f62e 100644 --- a/src/lib/p.hpp +++ b/src/lib/p.hpp @@ -133,6 +133,22 @@ namespace lib { + + /** Helper to create and manage by lib::P + * @tparam X the type of the new object to create on the heap + * @param ctorArgs arbitrary arguments to pass to ctor of `X` + * @return managing smart-ptr of type P, holding onto the + * object just created on the heap. + */ + template + inline P + newP (ARGS&&... ctorArgs) + { + return P{new X {std::forward(ctorArgs)...}}; + } + + + /** * use custom string conversion on pointee, if applicable, * otherwise fall back to a human readable type string.S @@ -141,7 +157,7 @@ namespace lib { inline P::operator std::string() const noexcept try { - if (this->get()) + if (BASE::get()) return meta::CustomStringConv::invoke (this->operator*()); else return "⟂ P<"+meta::typeStr(this->get())+">";