supplement: a "Make P" free function for our smart-ptr
the usual drill... only when wrapped into a factory function, RAII is really airtight, even when used from within expression evaluation. Thanks C++11 we're now able to provide such en passant
This commit is contained in:
parent
ed92b92158
commit
6ae8dc62c7
2 changed files with 18 additions and 9 deletions
|
|
@ -80,6 +80,7 @@ typedef unsigned int uint;
|
|||
#include <string>
|
||||
|
||||
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<typename X, typename...ARGS>
|
||||
inline P<X>
|
||||
newP (ARGS&&... ctorArgs)
|
||||
{
|
||||
return P<X>{new X {std::forward<ARGS>(ctorArgs)...}};
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
using BasicallyString = is_basically<T, string>;
|
||||
|
|
|
|||
|
|
@ -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<X>, holding onto the
|
||||
* object just created on the heap.
|
||||
*/
|
||||
template<typename X, typename...ARGS>
|
||||
inline P<X>
|
||||
newP (ARGS&&... ctorArgs)
|
||||
{
|
||||
return P<X>{new X {std::forward<ARGS>(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<TAR,BASE>::operator std::string() const noexcept
|
||||
try {
|
||||
if (this->get())
|
||||
if (BASE::get())
|
||||
return meta::CustomStringConv<TAR>::invoke (this->operator*());
|
||||
else
|
||||
return "⟂ P<"+meta::typeStr(this->get())+">";
|
||||
|
|
|
|||
Loading…
Reference in a new issue