C++ Utilities  4.17.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
memory.h
Go to the documentation of this file.
1 #ifndef MEMORY_H
2 #define MEMORY_H
3 
4 #include <memory>
5 
7 
8 #if __cplusplus <= 201103L
9 #define __cpp_lib_make_unique 201304
10 namespace std {
11 template <typename _Tp> struct _MakeUniq {
12  typedef unique_ptr<_Tp> __single_object;
13 };
14 
15 template <typename _Tp> struct _MakeUniq<_Tp[]> {
16  typedef unique_ptr<_Tp[]> __array;
17 };
18 
19 template <typename _Tp, size_t _Bound> struct _MakeUniq<_Tp[_Bound]> {
20  struct __invalid_type {
21  };
22 };
23 
25 template <typename _Tp, typename... _Args> inline typename _MakeUniq<_Tp>::__single_object make_unique(_Args &&... __args)
26 {
27  return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...));
28 }
29 
31 template <typename _Tp> inline typename _MakeUniq<_Tp>::__array make_unique(size_t __num)
32 {
33  return unique_ptr<_Tp>(new typename remove_extent<_Tp>::type[__num]());
34 }
35 
37 template <typename _Tp, typename... _Args> inline typename _MakeUniq<_Tp>::__invalid_type make_unique(_Args &&...) = delete;
38 } // namespace std
39 #endif
40 
42 
43 #endif // MEMORY_H