]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify some code with stuff from later C++ standards. 11238/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 24 Nov 2020 01:24:03 +0000 (18:24 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 24 Nov 2020 01:24:03 +0000 (18:24 -0700)
No need to re-invent wheels. It would be nice if we could have used std::is_base_of,
but that doesn't work because we don't know for sure which ones of the
possible BlockVectorBase<T> classes is the right base class, given that we don't
know T.

include/deal.II/lac/block_vector_base.h

index 8404da17b2e2ef81df568fec245c613e8ca6967d..870a6ae6355075515a8fa28a87ca87ab06f94519 100644 (file)
@@ -32,6 +32,7 @@
 #include <cmath>
 #include <cstddef>
 #include <iterator>
+#include <type_traits>
 #include <vector>
 
 DEAL_II_NAMESPACE_OPEN
@@ -65,28 +66,19 @@ template <typename VectorType>
 struct IsBlockVector
 {
 private:
-  struct yes_type
-  {
-    char c[1];
-  };
-  struct no_type
-  {
-    char c[2];
-  };
-
   /**
    * Overload returning true if the class is derived from BlockVectorBase,
    * which is what block vectors do.
    */
   template <typename T>
-  static yes_type
+  static std::true_type
   check_for_block_vector(const BlockVectorBase<T> *);
 
   /**
    * Catch all for all other potential vector types that are not block
    * matrices.
    */
-  static no_type
+  static std::false_type
   check_for_block_vector(...);
 
 public:
@@ -96,8 +88,8 @@ public:
    * derived from BlockVectorBase<T>).
    */
   static const bool value =
-    (sizeof(check_for_block_vector(static_cast<VectorType *>(nullptr))) ==
-     sizeof(yes_type));
+    std::is_same<decltype(check_for_block_vector(std::declval<VectorType *>())),
+                 std::true_type>::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.