]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a template constraint that checks if objects are iterable.
authorJean-Paul Pelteret <jppelteret@gmail.com>
Thu, 2 May 2019 17:27:32 +0000 (19:27 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Thu, 2 May 2019 17:27:32 +0000 (19:27 +0200)
include/deal.II/base/template_constraints.h

index 918b64328e35deb9c04b81994290aeab8104ad21..dc3a8be10dd0142e409acfe173a9609df24a2b16 100644 (file)
@@ -22,6 +22,7 @@
 #include <deal.II/base/complex_overloads.h>
 
 #include <complex>
+#include <iterator>
 #include <utility>
 
 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 <typename T>
+class has_begin_and_end
+{
+  template <typename C>
+  static std::false_type
+  test(...);
+
+  template <typename C>
+  static auto
+  test(int) -> decltype(std::begin(std::declval<C>()),
+                        std::end(std::declval<C>()),
+                        std::true_type());
+
+public:
+  using type = decltype(test<T>(0));
+
+  static const bool value = type::value;
+};
+
+
+
 template <bool, typename>
 struct constraint_and_return_value;
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.