#include <memory>
#include <utility>
using namespace std;
template< class Type, class... Args >
inline unique_ptr< Type > create( Args&&... args )
{
return unique_ptr< Type >( new Type( forward<Args>( args )... ) );
}
class Blah
: public enable_shared_from_this< Blah >
{
template< class Type> friend struct std::default_delete;
template< class Type > friend unique_ptr< Type > create( char const* );
private:
Blah& operator=( Blah const& ); // = delete
enum CreationKey{ creationKey };
protected:
Blah( Blah const& other )
: enable_shared_from_this( other )
{} // = default
virtual ~Blah(){} // Ensure dynamic alloc only.
static void* operator new( size_t const size )
{ return ::operator new( size ); }
public:
Blah() {}
Blah( int ) {}
Blah( char const* ) {}
};
int main()
{
//shared_ptr<Blah> p( new Blah( "blah" ) ); // !Nah.
shared_ptr<Blah> p( create<Blah>( "blah" ) );
shared_ptr<Blah> q = p->shared_from_this();
}