From: Martin Kronbichler Date: Thu, 12 May 2022 16:12:45 +0000 (+0200) Subject: Choose common SFINAE detection path for PreconditionChebyshev X-Git-Tag: v9.4.0-rc1~227^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13724%2Fhead;p=dealii.git Choose common SFINAE detection path for PreconditionChebyshev --- diff --git a/include/deal.II/lac/precondition.h b/include/deal.II/lac/precondition.h index fe72d7f478..6dd9bc2e7e 100644 --- a/include/deal.II/lac/precondition.h +++ b/include/deal.II/lac/precondition.h @@ -2500,60 +2500,39 @@ namespace internal solution.swap(solution_old); } - // Detector class to find out whether we have a vmult function that takes - // two additional std::function objects, which we use to run the operation - // on slices of the vector during the matrix-vector product + // a helper type-trait that leverage SFINAE to figure out if MatrixType has + // ... MatrixType::vmult(VectorType &, const VectorType&, + // std::function<...>, std::function<...>) const + template + using vmult_functions_t = decltype(std::declval().vmult( + std::declval(), + std::declval(), + std::declval< + const std::function &>(), + std::declval &>())); + template - struct supports_vmult_with_std_functions - { - private: - // this will work always - static bool - detect(...); - - // this detector will work only if we have - // "... MatrixType::vmult(VectorType, const VectorType, - // const std::function<...>&, const std::function<...>&) const" - template - static decltype(std::declval().vmult( - std::declval(), - std::declval(), - std::declval &>(), - std::declval &>())) - detect(const MatrixType2 &); - - public: - // finally here we check if our detector has void return type and - // fulfills additional requirements on the vector type and - // preconditioner. This will happen if the compiler can use the second - // detector, otherwise SFINAE let's it work with the more general first - // one that is bool - static const bool value = - !std::is_same())), - bool>::value && - std::is_same>::value && - std::is_same< - VectorType, - LinearAlgebra::distributed::Vector>::value; - }; + constexpr bool has_vmult_with_std_functions = + is_supported_operation + && std::is_same>::value + &&std::is_same< + VectorType, + LinearAlgebra::distributed::Vector>::value; // We need to have a separate declaration for static const members - template - const bool supports_vmult_with_std_functions::value; - template ::value, - int>::type * = nullptr> + template < + typename MatrixType, + typename VectorType, + typename PreconditionerType, + typename std::enable_if, + int>::type * = nullptr> inline void vmult_and_update(const MatrixType & matrix, const PreconditionerType &preconditioner, @@ -2579,14 +2558,14 @@ namespace internal solution); } - template ::value, - int>::type * = nullptr> + template < + typename MatrixType, + typename VectorType, + typename PreconditionerType, + typename std::enable_if, + int>::type * = nullptr> inline void vmult_and_update(const MatrixType & matrix, const PreconditionerType &preconditioner,