]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement std_cxx14::make_unique also for unbounded C-style arrays
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sat, 10 Feb 2018 14:20:03 +0000 (15:20 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 15 Feb 2018 20:54:28 +0000 (21:54 +0100)
include/deal.II/base/std_cxx14/memory.h

index e7f6d82bf50402989fd2f89adc514a72a543d38f..6970f5a069667cbc71f19baf7343f0ef9e942b7a 100644 (file)
@@ -30,15 +30,39 @@ namespace std_cxx14
 #ifdef DEAL_II_WITH_CXX14
   using std::make_unique;
 #else
+  namespace internal
+  {
+    template <typename T>
+    struct is_bounded_array
+    {
+      static constexpr bool value = false;
+    };
+
+    template <typename T, std::size_t N>
+    struct is_bounded_array<T[N]>
+    {
+      static constexpr bool value = true;
+    };
+  }
+
   template <typename T, typename... Args>
   inline
-  std::unique_ptr<T>
+  typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T> >::type
   make_unique(Args &&... constructor_arguments)
   {
-    static_assert(!std::is_array<T>::value,
-                  "This function is not implemented for array types.");
     return std::unique_ptr<T>(new T(std::forward<Args>(constructor_arguments)...));
   }
+
+  template <typename T>
+  inline
+  typename std::enable_if<std::is_array<T>::value, std::unique_ptr<T> >::type
+  make_unique(std::size_t n)
+  {
+    static_assert(!internal::is_bounded_array<T>::value,
+                  "This function is not implemented for bounded array types.");
+    return std::unique_ptr<T>(new typename std::remove_extent<T>::type [n]);
+  }
+
 #endif
 }
 DEAL_II_NAMESPACE_CLOSE

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.