From b3f7e6de98dc66c6108f4598ea649437911ffb10 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 18 Jul 2022 15:54:28 -0600 Subject: [PATCH] Declare 'enable_if_all_t' in analogy to std::enable_if_t. While there, also use it in fe_system.h. --- include/deal.II/base/template_constraints.h | 51 ++++++++++++++++++++- include/deal.II/fe/fe_system.h | 4 +- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/include/deal.II/base/template_constraints.h b/include/deal.II/base/template_constraints.h index 0d49d35b8f..fd333a27d1 100644 --- a/include/deal.II/base/template_constraints.h +++ b/include/deal.II/base/template_constraints.h @@ -259,7 +259,27 @@ struct is_same_as_any_of /* * A generalization of `std::enable_if` that only works if * all of the given boolean template parameters are - * true. + * true. See [here](https://en.cppreference.com/w/cpp/types/enable_if) + * for what `std::enable_if` does. + * + * @note + * In contrast to `std::enable_if`, this template has no additional + * template type (which for `std::enable_if` is defaulted to `void`). + * As a consequence, this structure cannot be used for anything other + * than enabling or disabling a template declaration; in particular + * it cannot be used to set the return type of a function as one might + * do with something like + * @code + * template + * typename std::enable_if::value, T>::type + * abs (const T t); + * @endcode + * which declares a function template `abs()` that can only be + * instantiated if `T` is a floating point type; this function then + * returns an object of type `T` as indicated by the last argument to + * `std::enable_if`. The reason `enable_if_all` does not allow providing + * this additional type is that variadic templates (here, the list of + * `bool` arguments) must be the last template argument. */ template struct enable_if_all @@ -268,6 +288,35 @@ struct enable_if_all +/* + * A generalization of `std::enable_if_t` that only works if + * all of the given boolean template parameters are + * true. See [here](https://en.cppreference.com/w/cpp/types/enable_if) + * for what `std::enable_if_t` does. + * + * @note + * In contrast to `std::enable_if_t`, this template has no additional + * template type (which for `std::enable_if` is defaulted to `void`). + * As a consequence, this structure cannot be used for anything other + * than enabling or disabling a template declaration; in particular + * it cannot be used to set the return type of a function as one might + * do with something like + * @code + * template + * std::enable_if_t::value, T> + * abs (const T t); + * @endcode + * which declares a function template `abs()` that can only be + * instantiated if `T` is a floating point type; this function then + * returns an object of type `T` as indicated by the last argument to + * `std::enable_if`. The reason `enable_if_all` does not allow providing + * this additional type is that variadic templates (here, the list of + * `bool` arguments) must be the last template argument. + */ +template +using enable_if_all_t = typename enable_if_all::type; + + /** * A type trait that checks to see if a class behaves as an iterable container * that has a beginning and an end. This implies that the class either defines diff --git a/include/deal.II/fe/fe_system.h b/include/deal.II/fe/fe_system.h index b834c4c95e..2a86623626 100644 --- a/include/deal.II/fe/fe_system.h +++ b/include/deal.II/fe/fe_system.h @@ -536,12 +536,12 @@ public: */ template < class... FEPairs, - typename = typename enable_if_all< + typename = enable_if_all_t< (std::is_same::type, std::pair>, unsigned int>>::value || std::is_base_of, - typename std::decay::type>::value)...>::type> + typename std::decay::type>::value)...>> FESystem(FEPairs &&...fe_pairs); /** -- 2.39.5