]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add enable_if_all template constraint class.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 15 Sep 2017 19:44:02 +0000 (13:44 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 17 Sep 2017 23:56:38 +0000 (17:56 -0600)
While there, simplify some other classes a bit by introducing
an 'all_true' class. Also move classes into a named internal
namespace.

include/deal.II/base/template_constraints.h

index fd28c0c3b9ed9c408a1667b3da531917de0e8a59..1455c9fe6ff9489ec0c91e62e9a5bfbc125c6ef3 100644 (file)
 
 DEAL_II_NAMESPACE_OPEN
 
-namespace
+namespace internal
 {
-  // helper struct for is_base_of_all and all_same_as
-  template <bool... Types> struct BoolStorage;
+  namespace TemplateConstraints
+  {
+    // helper struct for is_base_of_all and all_same_as
+    template <bool... Values> struct BoolStorage;
+
+
+    /**
+     * A helper class whose `value` member is true or false depending on
+    // whether all of the given boolean template arguments are true.
+     */
+    template <bool... Values>
+    struct all_true
+    {
+      static constexpr bool value =
+        std::is_same<BoolStorage<Values..., true>,
+        BoolStorage<true, Values...>>::value;
+    };
+  }
 }
 
 /**
@@ -41,27 +57,37 @@ 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;
+    internal::TemplateConstraints::all_true<std::is_base_of<Base,Derived>::value...>::value;
 };
 
 
 
 /**
  * This struct is a generalization of std::is_same to template
- * parameter packs and tests if all of the Types... classes are
- * in Type classes. The result is stored in the member variable value.
+ * parameter packs and tests if all of the types in the `Types...`
+ * parameter pack are equal to the `Type` given as first template
+ * argument. The result is stored in the member variable value.
  */
 template <class Type, class... Types>
 struct all_same_as
 {
   static constexpr bool value =
-    std::is_same<BoolStorage<std::is_same<Type, Types>::value..., true>,
-    BoolStorage<true, std::is_same<Type, Types>::value...>>::value;
+    internal::TemplateConstraints::all_true<std::is_same<Type, Types>::value...>::value;
 };
 
 
 
+/*
+ * A generalization of `std::enable_if` that only works if
+ * <i>all</i> of the given boolean template parameters are
+ * true.
+ */
+template <bool... Values>
+struct enable_if_all : std::enable_if<internal::TemplateConstraints::all_true<Values...>::value>
+{};
+
+
+
 template <bool, typename> struct constraint_and_return_value;
 
 

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.