AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
ForEach.hpp
1#pragma once
2
3#include <array>
4#include <tuple>
5#include <vector>
6#include <type_traits>
7#include <utility>
8
9#include <dune/common/tuplevector.hh>
10#include <amdis/common/ForEach.hpp>
11#include <amdis/common/TypeTraits.hpp>
12
13namespace AMDiS {
14namespace Recursive {
15
16template <class Vec>
17struct ForEach;
18
20
27template <class Container, class F>
28void forEach (Container&& container, F&& f)
29{
30 ForEach<TYPEOF(container)>::impl(container,f);
31}
32
33
34// specializations for container types
35
36
37template <class>
38struct ForEach
39{
40private:
41 // ranges with dynamic index access
42 template <class Vec, class F,
43 class = decltype(std::begin(std::declval<Vec>())),
44 class = decltype(std::end(std::declval<Vec>()))>
45 static void impl2 (Dune::PriorityTag<2>, Vec&& vec, F&& f)
46 {
47 for (auto&& v : vec)
48 Recursive::forEach(v, f);
49 }
50
51 // ranges with static index access
52 template <class Vec, class F,
53 class = decltype(std::get<0>(std::declval<Vec>()))>
54 static void impl2 (Dune::PriorityTag<1>, Vec&& vec, F&& f)
55 {
56 Ranges::forEach(vec, [&](auto&& v) {
57 Recursive::forEach(v, f);
58 });
59 }
60
61 // no range
62 template <class Value, class F>
63 static void impl2 (Dune::PriorityTag<0>, Value&& value, F&& f)
64 {
65 f(value);
66 }
67
68public:
69 template <class Vec, class F>
70 static void impl (Vec&& vec, F&& f)
71 {
72 impl2(Dune::PriorityTag<5>{}, vec, f);
73 }
74};
75
76}} // end namespace AMDiS::Recursive
Definition: ForEach.hpp:39