DIY 3.0 data-parallel out-of-core C++ library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List

All Classes Namespaces Functions Typedefs Groups Pages
vertices.hpp
1 #ifndef DIY_VERTICES_HPP
2 #define DIY_VERTICES_HPP
3
4 #include <iterator>
5
6 namespace diy
7 {
8
9 namespace detail
10 {
11 template<class Vertex, size_t I>
12 struct IsLast
13 {
14 static constexpr bool value = (Vertex::dimension() - 1 == I);
15 };
16
17 template<class Vertex, class Callback, size_t I, bool P>
18 struct ForEach
19 {
20 void operator()(Vertex& pos, const Vertex& from, const Vertex& to, const Callback& callback) const
21 {
22 for (pos[I] = from[I]; pos[I] <= to[I]; ++pos[I])
23 ForEach<Vertex, Callback, I+1, IsLast<Vertex,I+1>::value>()(pos, from, to, callback);
24 }
25 };
26
27 template<class Vertex, class Callback, size_t I>
28 struct ForEach<Vertex,Callback,I,true>
29 {
30 void operator()(Vertex& pos, const Vertex& from, const Vertex& to, const Callback& callback) const
31 {
32 for (pos[I] = from[I]; pos[I] <= to[I]; ++pos[I])
33 callback(pos);
34 }
35 };
36 }
37
38 template<class Vertex, class Callback>
39 void for_each(const Vertex& from, const Vertex& to, const Callback& callback)
40 {
41 Vertex pos;
42 grid::detail::ForEach<Vertex, Callback, 0, detail::IsLast<Vertex,0>::value>()(pos, from, to, callback);
43 }
44
45 template<class Vertex, class Callback>
46 void for_each(const Vertex& shape, const Callback& callback)
47 {
48 // specify grid namespace to disambiguate with std::for_each(...)
49 grid::for_each(Vertex::zero(), shape - Vertex::one(), callback);
50 }
51
52 }
53
54 #endif