SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
some.h
Go to the documentation of this file.
1 #ifndef __SG_SOME_H__
2 #define __SG_SOME_H__
3 
4 #include <shogun/lib/config.h>
5 
6 #ifdef HAVE_CXX11
7 #include <memory>
8 
9 #include <shogun/base/SGObject.h>
10 
11 namespace shogun
12 {
13 
25  template <typename T>
26  class Some : protected std::shared_ptr<T>
27  {
28  public:
29  Some() = delete;
30  Some(const std::shared_ptr<T>& shared);
31  Some(const Some<T>& other);
32  Some(Some<T>&& other);
33  Some& operator=(const Some<T>& other);
34  ~Some();
35 
40  operator T*();
45  T* operator->();
46  private:
47  using std::shared_ptr<T>::get;
48  };
49 
50  template <typename T>
51  Some<T>::Some(const std::shared_ptr<T>& shared)
52  : std::shared_ptr<T>(shared)
53  {
54  }
55  template <typename T>
56  Some<T>::Some(const Some<T>& other)
57  : std::shared_ptr<T>(other)
58  {
59  }
60  template <typename T>
61  Some<T>::Some(Some<T>&& other)
62  : std::shared_ptr<T>(other)
63  {
64  }
65  template <typename T>
66  Some<T>::~Some()
67  {
68  }
69  template <typename T>
70  Some<T>::operator T*()
71  {
72  T* ptr = this->get();
73  SG_REF(ptr);
74  return ptr;
75  }
76  template <typename T>
77  T* Some<T>::operator->()
78  {
79  T* ptr = this->get();
80  return ptr;
81  }
82 
93  template <typename T, class... Args>
94  Some<T> some(Args&&... args)
95  {
96  T* ptr = new T(args...);
97  SG_REF(ptr);
98  return std::shared_ptr<T>(ptr, [](T* p) { SG_UNREF(p); });
99  }
100 
101 };
102 
103 #endif /* HAVE_CXX11 */
104 #endif /* __SG_SOME_H__ */
#define SG_REF(x)
Definition: SGObject.h:51
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18

SHOGUN Machine Learning Toolbox - Documentation