From 9823a98a4dbc86ee79852e7af9b75d772e5d2205 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 1 Mar 2022 14:22:39 -0700 Subject: [PATCH] Provide a facility where we can test that a type is one of a list. --- include/deal.II/base/template_constraints.h | 45 ++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/include/deal.II/base/template_constraints.h b/include/deal.II/base/template_constraints.h index 1d39f1b1d7..6b254638fe 100644 --- a/include/deal.II/base/template_constraints.h +++ b/include/deal.II/base/template_constraints.h @@ -170,7 +170,11 @@ namespace internal /** * A helper class whose `value` member is true or false depending on - * whether all of the given boolean template arguments are true. + * whether all of the given boolean template arguments are `true`. + * The class works by comparing the list of boolean values + * `true, Values...` with the list `Values..., true` (i.e., with + * its rotated self). The two are only the same if `Values...` is + * a list of only `true` values. */ template struct all_true @@ -179,6 +183,28 @@ namespace internal std::is_same, BoolStorage>::value; }; + + + /** + * A class whose `value` member is set to `true` if any of the + * boolean template arguments are true. + */ + template + struct any_true; + + + template + struct any_true + { + static constexpr bool value = V1 || any_true::value; + }; + + + template <> + struct any_true<> + { + static constexpr bool value = false; + }; } // namespace TemplateConstraints } // namespace internal @@ -201,7 +227,7 @@ struct is_base_of_all * This struct is a generalization of std::is_same to template * parameter packs and tests if all of the types in the `Types...` * parameter pack are equal to the `Type` given as first template - * argument. The result is stored in the member variable value. + * argument. The result is stored in the member variable `value`. */ template struct all_same_as @@ -212,6 +238,21 @@ struct all_same_as +/** + * This struct is a generalization of std::is_same to template + * parameter packs and tests if any of the types in the `Types...` + * parameter pack are equal to the `Type` given as first template + * argument. The result is stored in the member variable `value`. + */ +template +struct is_same_as_any_of +{ + static constexpr bool value = internal::TemplateConstraints::any_true< + std::is_same::value...>::value; +}; + + + /* * A generalization of `std::enable_if` that only works if * all of the given boolean template parameters are -- 2.39.5