2016-08-26 21:25:05 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
2017-11-04 03:20:18 +00:00
|
|
|
/** 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
|
2017-11-04 03:20:18 +00:00
|
|
|
* and you will have static 'create' method in your class.
|
2016-10-23 07:41:26 +00:00
|
|
|
*/
|
|
|
|
template <typename T>
|
2017-11-03 21:50:22 +00:00
|
|
|
struct shared_ptr_helper
|
2016-08-26 21:25:05 +00:00
|
|
|
{
|
2017-06-06 18:36:13 +00:00
|
|
|
template <typename... TArgs>
|
2019-08-26 19:07:29 +00:00
|
|
|
static std::shared_ptr<T> create(TArgs &&... args)
|
2017-06-06 18:36:13 +00:00
|
|
|
{
|
2019-08-26 19:07:29 +00:00
|
|
|
return std::shared_ptr<T>(new T(std::forward<TArgs>(args)...));
|
2017-06-06 18:36:13 +00:00
|
|
|
}
|
2016-08-26 21:25:05 +00:00
|
|
|
};
|
|
|
|
|
2019-11-09 15:31:56 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct is_shared_ptr
|
|
|
|
{
|
|
|
|
static constexpr bool value = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct is_shared_ptr<std::shared_ptr<T>>
|
|
|
|
{
|
|
|
|
static constexpr bool value = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline constexpr bool is_shared_ptr_v = is_shared_ptr<T>::value;
|