Reference documentation for deal.II version 9.0.0
memory.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 #ifndef dealii_cxx14_memory_h
16 #define dealii_cxx14_memory_h
17 
18 #include <deal.II/base/config.h>
19 
20 #include <memory>
21 
22 #ifndef DEAL_II_WITH_CXX14
23 // needed for array type check
24 # include <type_traits>
25 #endif
26 
27 DEAL_II_NAMESPACE_OPEN
28 namespace std_cxx14
29 {
30 #ifdef DEAL_II_WITH_CXX14
31  using std::make_unique;
32 #else
33  namespace internal
34  {
35  template <typename T>
36  struct is_bounded_array
37  {
38  static constexpr bool value = false;
39  };
40 
41  template <typename T, std::size_t N>
42  struct is_bounded_array<T[N]>
43  {
44  static constexpr bool value = true;
45  };
46  }
47 
48  template <typename T, typename... Args>
49  inline
50  typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T> >::type
51  make_unique(Args &&... constructor_arguments)
52  {
53  return std::unique_ptr<T>(new T(std::forward<Args>(constructor_arguments)...));
54  }
55 
56  template <typename T>
57  inline
58  typename std::enable_if<std::is_array<T>::value, std::unique_ptr<T> >::type
59  make_unique(std::size_t n)
60  {
61  static_assert(!internal::is_bounded_array<T>::value,
62  "This function is not implemented for bounded array types.");
63  return std::unique_ptr<T>(new typename std::remove_extent<T>::type [n]);
64  }
65 
66 #endif
67 }
68 DEAL_II_NAMESPACE_CLOSE
69 
70 #endif // dealii_cxx14_memory_h