]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Generalize IsBlockVector 13605/head
authorPeter Munch <peterrmuench@gmail.com>
Sat, 9 Apr 2022 19:11:25 +0000 (21:11 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Sat, 9 Apr 2022 19:18:59 +0000 (21:18 +0200)
include/deal.II/lac/block_vector_base.h

index 90e602c51ba1a59cfea0e38d7e5a23a7206d61da..3e8d2383ddeb3687a9f5e1eeff38102fc33228d8 100644 (file)
@@ -42,11 +42,24 @@ DEAL_II_NAMESPACE_OPEN
  *@{
  */
 
-// Forward declaration
-#ifndef DOXYGEN
-template <typename>
-class BlockVectorBase;
-#endif
+namespace internal
+{
+  template <typename T>
+  using has_block_t = decltype(std::declval<T const>().block(0));
+
+  template <typename T>
+  constexpr bool has_block = internal::is_supported_operation<has_block_t, T>;
+
+  template <typename T>
+  using has_n_blocks_t = decltype(std::declval<T const>().n_blocks());
+
+  template <typename T>
+  constexpr bool has_n_blocks =
+    internal::is_supported_operation<has_n_blocks_t, T>;
+
+  template <typename T>
+  constexpr bool is_block_vector = has_block<T> &&has_n_blocks<T>;
+} // namespace internal
 
 /**
  * A class that can be used to determine whether a given type is a block
@@ -65,31 +78,13 @@ class BlockVectorBase;
 template <typename VectorType>
 struct IsBlockVector
 {
-private:
-  /**
-   * Overload returning true if the class is derived from BlockVectorBase,
-   * which is what block vectors do.
-   */
-  template <typename T>
-  static std::true_type
-  check_for_block_vector(const BlockVectorBase<T> *);
-
-  /**
-   * Catch all for all other potential vector types that are not block
-   * vectors.
-   */
-  static std::false_type
-  check_for_block_vector(...);
-
 public:
   /**
    * A statically computable value that indicates whether the template
-   * argument to this class is a block vector (in fact whether the type is
-   * derived from BlockVectorBase<T>).
+   * argument to this class is a block vector (in fact whether the type has
+   * the functions `block()` and `n_blocks()`).
    */
-  static const bool value =
-    std::is_same<decltype(check_for_block_vector(std::declval<VectorType *>())),
-                 std::true_type>::value;
+  static const bool value = internal::is_block_vector<VectorType>;
 };
 
 

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.