From: Jean-Paul Pelteret Date: Thu, 2 May 2019 17:27:32 +0000 (+0200) Subject: Add a template constraint that checks if objects are iterable. X-Git-Tag: v9.1.0-rc1~126^2~7 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65a2cee3cbccae85a0e8ee99476a7b8f9c3e6d5c;p=dealii.git Add a template constraint that checks if objects are iterable. --- diff --git a/include/deal.II/base/template_constraints.h b/include/deal.II/base/template_constraints.h index 918b64328e..dc3a8be10d 100644 --- a/include/deal.II/base/template_constraints.h +++ b/include/deal.II/base/template_constraints.h @@ -22,6 +22,7 @@ #include #include +#include #include DEAL_II_NAMESPACE_OPEN @@ -91,6 +92,32 @@ struct enable_if_all +/** + * 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 + * the `begin()` and `end()` functions, or is a C-style array. + */ +template +class has_begin_and_end +{ + template + static std::false_type + test(...); + + template + static auto + test(int) -> decltype(std::begin(std::declval()), + std::end(std::declval()), + std::true_type()); + +public: + using type = decltype(test(0)); + + static const bool value = type::value; +}; + + + template struct constraint_and_return_value;