Just a bit of fun wrapping JUCE’s smart pointers in make functions, similar to std::make_unique and std::make_shared.
/** This can be used to create a 'makeCustomSmartPointerType' function. */
#define CREATE_MAKE_PTR_TYPE(CustomSmartPointerType) \
template<class Type, class... ConstructorInitList> \
inline typename std::enable_if<! std::is_array<Type>::value, CustomSmartPointerType<Type>>::type make##CustomSmartPointerType (ConstructorInitList&&... args) \
{ \
return CustomSmartPointerType<Type> (new Type (std::forward<ConstructorInitList> (args)...)); \
}
/** This creates a 'make' function in conjunction with juce::ScopedPointer. */
CREATE_MAKE_PTR_TYPE (ScopedPointer)
/** This creates a 'make' function in conjunction with juce::ReferenceCountedObjectPtr. */
CREATE_MAKE_PTR_TYPE (ReferenceCountedObjectPtr)
Usage example:
auto element = makeScopedPointer<XmlElement> ("ElementName");
