1#pragma once
2
3#include <memory>
4
5namespace ext
6{
7
8/** Allows to make std::shared_ptr from T with protected constructor.
9 *
10 * Derive your T class from shared_ptr_helper<T> and add shared_ptr_helper<T> as a friend
11 * and you will have static 'create' method in your class.
12 */
13template <typename T>
14struct shared_ptr_helper
15{
16 template <typename... TArgs>
17 static std::shared_ptr<T> create(TArgs &&... args)
18 {
19 return std::shared_ptr<T>(new T(std::forward<TArgs>(args)...));
20 }
21};
22
23
24template <typename T>
25struct is_shared_ptr
26{
27 static constexpr bool value = false;
28};
29
30
31template <typename T>
32struct is_shared_ptr<std::shared_ptr<T>>
33{
34 static constexpr bool value = true;
35};
36
37template <typename T>
38inline constexpr bool is_shared_ptr_v = is_shared_ptr<T>::value;
39}
40