From: Wolfgang Bangerth Date: Mon, 18 Jul 2022 21:54:28 +0000 (-0600) Subject: Declare 'enable_if_all_t' in analogy to std::enable_if_t. X-Git-Tag: v9.5.0-rc1~1076^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3f7e6de98dc66c6108f4598ea649437911ffb10;p=dealii.git Declare 'enable_if_all_t' in analogy to std::enable_if_t. While there, also use it in fe_system.h. --- 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); /**