From: Peter Munch Date: Sat, 9 Apr 2022 19:11:25 +0000 (+0200) Subject: Generalize IsBlockVector X-Git-Tag: v9.4.0-rc1~320^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2eb751395c7a74c6b4781b788a441f6c8d82d09d;p=dealii.git Generalize IsBlockVector --- diff --git a/include/deal.II/lac/block_vector_base.h b/include/deal.II/lac/block_vector_base.h index 90e602c51b..3e8d2383dd 100644 --- a/include/deal.II/lac/block_vector_base.h +++ b/include/deal.II/lac/block_vector_base.h @@ -42,11 +42,24 @@ DEAL_II_NAMESPACE_OPEN *@{ */ -// Forward declaration -#ifndef DOXYGEN -template -class BlockVectorBase; -#endif +namespace internal +{ + template + using has_block_t = decltype(std::declval().block(0)); + + template + constexpr bool has_block = internal::is_supported_operation; + + template + using has_n_blocks_t = decltype(std::declval().n_blocks()); + + template + constexpr bool has_n_blocks = + internal::is_supported_operation; + + template + constexpr bool is_block_vector = has_block &&has_n_blocks; +} // namespace internal /** * A class that can be used to determine whether a given type is a block @@ -65,31 +78,13 @@ class BlockVectorBase; template struct IsBlockVector { -private: - /** - * Overload returning true if the class is derived from BlockVectorBase, - * which is what block vectors do. - */ - template - static std::true_type - check_for_block_vector(const BlockVectorBase *); - - /** - * 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). + * 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())), - std::true_type>::value; + static const bool value = internal::is_block_vector; };