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

SHOGUN Machine Learning Toolbox - Documentation