]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Improve error message in hp::FECollection constructor 4922/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Mon, 21 Aug 2017 14:28:50 +0000 (16:28 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Mon, 21 Aug 2017 16:11:21 +0000 (18:11 +0200)
doc/news/changes/minor/20170821DanielArndt [new file with mode: 0644]
include/deal.II/base/template_constraints.h
include/deal.II/hp/fe_collection.h

diff --git a/doc/news/changes/minor/20170821DanielArndt b/doc/news/changes/minor/20170821DanielArndt
new file mode 100644 (file)
index 0000000..13cfe6a
--- /dev/null
@@ -0,0 +1,5 @@
+New: The struct is_base_of_all is a generalization of std::is_base_of
+to template parameter packs and tests if all classes in the parameter pack
+have a given class as base class or are this class.
+<br>
+(Daniel Arndt, 2017/08/21)
index 0589d03baefbc056ceb454f8f3018e67ff39ac44..908d85e12df35208567e2728b823e993e0fefcb8 100644 (file)
 
 DEAL_II_NAMESPACE_OPEN
 
+namespace
+{
+  // helper struct for is_base_of_all
+  template<bool... Types> struct BoolStorage;
+}
+
+/**
+ * This struct is a generalization of std::is_base_of<Base, Derived>
+ * to template parameter packs and tests if all of the Derived...
+ * classes have Base as base class or are Base itself. The result
+ * is stored in the member variable value.
+ */
+template<class Base, class... Derived>
+struct is_base_of_all
+{
+  static constexpr bool value =
+    std::is_same<BoolStorage<std::is_base_of<Base,Derived>::value..., true>,
+    BoolStorage<true, std::is_base_of<Base,Derived>::value...>>::value;
+};
+
+
+
 template <bool, typename> struct constraint_and_return_value;
 
 
index f81839f2aba421d0a3eb17f67c60cd44c69faf3b..6ed435e74d7207e8f825b8e29dc098744a0451e1 100644 (file)
@@ -454,6 +454,18 @@ namespace hp
   template <class... FETypes>
   FECollection<dim,spacedim>::FECollection (const FETypes &... fes)
   {
+    static_assert(is_base_of_all<FiniteElement<dim, spacedim>, FETypes...>::value,
+                  "Not all of the input parameters are derived from FiniteElement<dim, spacedim>!");
+
+    // We want to call 'push_back' for each of the arguments. To do so parameter
+    // pack expansion comes in handy. Unfortunately, we can't just write
+    //   push_back(fes)...;
+    // but have to treat this as arguments to some function which doesn't need
+    // to do anything with it. Now,
+    //   [](...) {}(push_back(fes)...);
+    // doesn't work as well because the ellipsis cannot deal with no parameters
+    // at all. Hence, we extend the return value of each of the return values
+    // by zero using the comma operator.
     [](...) {}((push_back(fes),0)...);
   }
 

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.