Dune Core Modules (2.6.0)

memory.hh
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
9namespace Dune
10{
11
12 namespace Std
13 {
14
15#if DUNE_HAVE_CXX_MAKE_UNIQUE
16
17 using std::make_unique;
18
19#else
20
21#ifndef DOXYGEN
22
23 namespace Impl {
24
25 // Helper struct to distinguish non-array, unknown bound
26 // array, and known bound array types using SFINAE
27 // following proposal N3656 by Stephan T. Lavavej.
28
29 template<class T>
30 struct MakeUniqueHelper
31 {
32 typedef std::unique_ptr<T> NonArrayUniquePtr;
33 };
34
35 template<class T>
36 struct MakeUniqueHelper<T[]>
37 {
38 typedef std::unique_ptr<T[]> UnknownBoundArrayUniquePtr;
39 typedef T RawType;
40 };
41
42 template<class T, size_t N>
43 struct MakeUniqueHelper<T[N]>
44 {
45 typedef void KnownBoundArrayUniquePtr;
46 };
47
48 }
49
50#endif // DOXYGEN
51
64 template<typename T, typename... Args>
65 typename Impl::MakeUniqueHelper<T>::NonArrayUniquePtr
66 make_unique(Args&&... args)
67 {
68 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
69 }
70
79 template<typename T>
80 typename Impl::MakeUniqueHelper<T>::UnknownBoundArrayUniquePtr
81 make_unique(size_t n)
82 {
83 return std::unique_ptr<T>(new typename Impl::MakeUniqueHelper<T>::RawType[n]());
84 }
85
98 template<typename T, typename ...Args>
99 typename Impl::MakeUniqueHelper<T>::KnownBoundArrayUniquePtr
100 make_unique(Args&&... args) = delete;
101
102#endif // DUNE_HAVE_CXX_MAKE_UNIQUE
103
104 } // namespace Std
105
106} // namespace Dune
107
108#endif // #ifndef DUNE_COMMON_STD_MEMORY_HH
Impl::MakeUniqueHelper< T >::KnownBoundArrayUniquePtr make_unique(Args &&... args)=delete
Implementation of std::make_unique to be introduced in C++14.
Definition: memory.hh:66
Dune namespace.
Definition: alignedallocator.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)