Reference documentation for deal.II version 9.1.0-pre
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.md at
12 // the top level directory of deal.II.
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  } // namespace internal
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>(
54  new T(std::forward<Args>(constructor_arguments)...));
55  }
56 
57  template <typename T>
58  inline
59  typename std::enable_if<std::is_array<T>::value, std::unique_ptr<T>>::type
60  make_unique(std::size_t n)
61  {
62  static_assert(!internal::is_bounded_array<T>::value,
63  "This function is not implemented for bounded array types.");
64  return std::unique_ptr<T>(new typename std::remove_extent<T>::type[n]);
65  }
66 
67 #endif
68 } // namespace std_cxx14
69 DEAL_II_NAMESPACE_CLOSE
70 
71 #endif // dealii_cxx14_memory_h