ADTF  3.18.2
unique_ptr.h
Go to the documentation of this file.
1 
19 #ifndef A_UTIL_UTIL_MEMORY_UNIQUE_PTR_HEADER_INCLUDED
20 #define A_UTIL_UTIL_MEMORY_UNIQUE_PTR_HEADER_INCLUDED
21 
22 #include <memory>
23 
24 namespace a_util {
25 namespace memory {
30 using ::std::unique_ptr;
31 
32 #if (!defined(_MSC_VER) && !(__cplusplus > 201103L)) || \
33  (defined(_MSC_VER) && (_MSC_VER < 1800)) || defined(A_UTIL_ENABLE_MAKE_UNIQUE)
34 
36 template <class T>
37 struct _Unique_if {
38  typedef unique_ptr<T> _Single_object;
39 };
40 
41 template <class T>
42 struct _Unique_if<T[]> {
43  typedef unique_ptr<T[]> _Unknown_bound;
44 };
45 
46 template <class T, size_t N>
47 struct _Unique_if<T[N]> {
48  typedef void _Known_bound;
49 };
67 template <class T, class... Args>
68 typename _Unique_if<T>::_Single_object make_unique(Args&&... args)
69 {
70  return unique_ptr<T>(new T(std::forward<Args>(args)...));
71 }
72 
87 template <class T>
88 typename _Unique_if<T>::_Unknown_bound make_unique(size_t n)
89 {
90  typedef typename std::remove_extent<T>::type U;
91  return unique_ptr<T>(new U[n]());
92 }
93 
107 template <class T, class... Args>
108 typename _Unique_if<T>::_Known_bound make_unique(Args&&...) = delete;
109 
110 #else
111 
118 
119 #endif // defined(A_UTIL_ENABLE_MAKE_UNIQUE)
120 
121 } // namespace memory
122 } // namespace a_util
123 
124 #endif // A_UTIL_UTIL_MEMORY_UNIQUE_PTR_HEADER_INCLUDED
_Unique_if< T >::_Single_object make_unique(Args &&... args)
Compatibility to C++14 std::make_unique for non-array types.
Definition: unique_ptr.h:68
_Unique_if< T >::_Known_bound make_unique(Args &&...)=delete
Compatibility to C++14 std::make_unique to disallow construction of arrays of known bound.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:24