From 659e1d2c64c2001bb5d28562603ce33594272b59 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 15 Sep 2017 13:44:02 -0600 Subject: [PATCH] Add enable_if_all template constraint class. While there, simplify some other classes a bit by introducing an 'all_true' class. Also move classes into a named internal namespace. --- include/deal.II/base/template_constraints.h | 44 ++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/include/deal.II/base/template_constraints.h b/include/deal.II/base/template_constraints.h index fd28c0c3b9..1455c9fe6f 100644 --- a/include/deal.II/base/template_constraints.h +++ b/include/deal.II/base/template_constraints.h @@ -25,10 +25,26 @@ DEAL_II_NAMESPACE_OPEN -namespace +namespace internal { - // helper struct for is_base_of_all and all_same_as - template struct BoolStorage; + namespace TemplateConstraints + { + // helper struct for is_base_of_all and all_same_as + template struct BoolStorage; + + + /** + * A helper class whose `value` member is true or false depending on + // whether all of the given boolean template arguments are true. + */ + template + struct all_true + { + static constexpr bool value = + std::is_same, + BoolStorage>::value; + }; + } } /** @@ -41,27 +57,37 @@ template struct is_base_of_all { static constexpr bool value = - std::is_same::value..., true>, - BoolStorage::value...>>::value; + internal::TemplateConstraints::all_true::value...>::value; }; /** * This struct is a generalization of std::is_same to template - * parameter packs and tests if all of the Types... classes are - * in Type classes. The result is stored in the member variable value. + * 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. */ template struct all_same_as { static constexpr bool value = - std::is_same::value..., true>, - BoolStorage::value...>>::value; + internal::TemplateConstraints::all_true::value...>::value; }; +/* + * A generalization of `std::enable_if` that only works if + * all of the given boolean template parameters are + * true. + */ +template +struct enable_if_all : std::enable_if::value> +{}; + + + template struct constraint_and_return_value; -- 2.39.5