From 6bf718672dac63c3472590d8f8bab16ed0f525b0 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 24 Jan 2022 18:17:02 -0500 Subject: [PATCH] Use standardized detection idiom --- include/deal.II/base/template_constraints.h | 82 +++++-- include/deal.II/lac/la_parallel_vector.h | 73 ++----- include/deal.II/lac/precondition.h | 178 ++++------------ include/deal.II/matrix_free/matrix_free.h | 19 +- include/deal.II/matrix_free/type_traits.h | 224 ++++---------------- 5 files changed, 169 insertions(+), 407 deletions(-) diff --git a/include/deal.II/base/template_constraints.h b/include/deal.II/base/template_constraints.h index 6a253619b0..31c4fab041 100644 --- a/include/deal.II/base/template_constraints.h +++ b/include/deal.II/base/template_constraints.h @@ -27,6 +27,68 @@ DEAL_II_NAMESPACE_OPEN +template +using void_t = void; + +// Detection idiom from Version 2 of the C++ Extensions for Library +// Fundamentals, ISO/IEC TS 19568:2017 + +namespace internal +{ + // base class for nonesuch to inherit from so it is not an aggregate + struct nonesuch_base + {}; + + // primary template handles all types not supporting the archetypal Op + template + class Op, + class... /*Args*/> + struct detector + { + using value_t = std::false_type; + using type = Default; + }; + + // specialization recognizes and handles only types supporting Op + template class Op, class... Args> + struct detector>, Op, Args...> + { + using value_t = std::true_type; + using type = Op; + }; +} // namespace internal + +struct nonesuch : private internal::nonesuch_base +{ + ~nonesuch() = delete; + nonesuch(nonesuch const &) = delete; + void + operator=(nonesuch const &) = delete; +}; + +template class Op, class... Args> +using detected_or = internal::detector; + +template