Dune Core Modules (2.5.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 // 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>
20 struct MakeUniqueHelper
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 {
35 typedef void KnownBoundArrayUniquePtr;
36 };
37
38
49 template<typename T, typename... Args>
50 typename MakeUniqueHelper<T>::NonArrayUniquePtr
51 make_unique(Args&&... args)
52 {
53 return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
54 }
55
62 template<typename T>
63 typename MakeUniqueHelper<T>::UnknownBoundArrayUniquePtr
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>
80 typename MakeUniqueHelper<T>::KnownBoundArrayUniquePtr
81 make_unique(Args&&... args) = delete;
82
83
84 } // namespace Std
85
86} // namespace Dune
87
88#endif // #ifndef DUNE_COMMON_STD_MEMORY_HH
Dune namespace.
Definition: alignment.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)