Skip to content

Commit

Permalink
SP: Added Zone::UniquePtr typedef
Browse files Browse the repository at this point in the history
Saves having to write `std::unique_ptr< X, Zone::Deleter >` instead of `Zone::UniquePtr< X >`
  • Loading branch information
mrwonko committed Nov 9, 2015
1 parent 3b26abb commit d03f17d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions code/qcommon/safe/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,20 @@ namespace Zone
using other = Allocator< U, tag >;
};
};

template< typename T >
using UniquePtr = std::unique_ptr< T, Deleter >;

/**
make_unique using Zone Allocations (with appropriate deleter)
*/
template< typename T, memtag_t tag, typename... Args >
inline std::unique_ptr< T, Deleter > make_unique( Args&&... args )
inline UniquePtr< T > make_unique( Args&&... args )
{
std::unique_ptr< void, Deleter > memory( Allocator< T, tag >{}.allocate( 1 ) );
UniquePtr< void > memory( Allocator< T, tag >{}.allocate( 1 ) );
// placement new. may throw, in which case the unique_ptr will take care of freeing the memory.
T* obj = new( memory )T( std::forward< Args >( args )... );
memory.release();
return std::unique_ptr< T, Deleter >( obj );
return UniquePtr< T >( obj );
}
}

0 comments on commit d03f17d

Please sign in to comment.