ClickHouse/libs/libcommon/include/ext/shared_ptr_helper.h

24 lines
508 B
C++
Raw Normal View History

#pragma once
#include <memory>
namespace ext
{
/** Allows to make std::shared_ptr from T with protected constructor.
*
2019-08-26 19:07:29 +00:00
* Derive your T class from shared_ptr_helper<T> and add shared_ptr_helper<T> as a friend
* and you will have static 'create' method in your class.
2016-10-23 07:41:26 +00:00
*/
template <typename T>
struct shared_ptr_helper
{
template <typename... TArgs>
2019-08-26 19:07:29 +00:00
static std::shared_ptr<T> create(TArgs &&... args)
{
2019-08-26 19:07:29 +00:00
return std::shared_ptr<T>(new T(std::forward<TArgs>(args)...));
}
};
}