dune-common  2.5.0
memory.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set ts=8 sw=2 et sts=2:
3 #ifndef DUNE_COMMON_STD_MEMORY_HH
4 #define DUNE_COMMON_STD_MEMORY_HH
5 
6 #include <memory>
7 #include <utility>
8 
9 namespace Dune
10 {
11 
12  namespace Std
13  {
14 
15  // Helper struct to distinguish non-array, unknown bound
16  // array, and known bound array types using SFINAE
17  // following proposal N3656 by Stephan T. Lavavej.
18 
19  template<class T>
21  {
22  typedef std::unique_ptr<T> NonArrayUniquePtr;
23  };
24 
25  template<class T>
26  struct MakeUniqueHelper<T[]>
27  {
28  typedef std::unique_ptr<T[]> UnknownBoundArrayUniquePtr;
29  typedef T RawType;
30  };
31 
32  template<class T, size_t N>
33  struct MakeUniqueHelper<T[N]>
34  {
36  };
37 
38 
49  template<typename T, typename... Args>
51  make_unique(Args&&... args)
52  {
53  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
54  }
55 
62  template<typename T>
64  make_unique(size_t n)
65  {
66  return std::unique_ptr<T>(new typename MakeUniqueHelper<T>::RawType[n]());
67  }
68 
79  template<typename T, typename ...Args>
81  make_unique(Args&&... args) = delete;
82 
83 
84  } // namespace Std
85 
86 } // namespace Dune
87 
88 #endif // #ifndef DUNE_COMMON_STD_MEMORY_HH
std::unique_ptr< T[]> UnknownBoundArrayUniquePtr
Definition: memory.hh:28
Definition: memory.hh:20
std::unique_ptr< T > NonArrayUniquePtr
Definition: memory.hh:22
Dune namespace.
Definition: alignment.hh:10
T RawType
Definition: memory.hh:29
void KnownBoundArrayUniquePtr
Definition: memory.hh:35
MakeUniqueHelper< T >::NonArrayUniquePtr make_unique(Args &&... args)
Implementation of std::make_unique to be introduced in C++14.
Definition: memory.hh:51