Dune Core Modules (2.3.1)

forloop.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_COMMON_FORLOOP_HH
5#define DUNE_COMMON_FORLOOP_HH
6
12
13namespace Dune
14{
15
16#ifndef DOXYGEN
17 // GenericForLoop
18 // --------------
19
20 template< template< class, class > class Operation, template< int > class Value, int first, int last >
21 class GenericForLoop
22 : public Operation< Value< first >, GenericForLoop< Operation, Value, first+1, last > >
23 {
24 dune_static_assert( (first <= last), "GenericForLoop: first > last" );
25 };
26
27 template< template< class, class > class Operation, template< int > class Value, int last >
28 class GenericForLoop< Operation, Value, last, last >
29 : public Value< last >
30 {};
31
32 // ForLoopHelper
33 // -------------
34
35 namespace ForLoopHelper
36 {
37
38 template< class A, class B >
39 struct Apply
40 {
41 static void apply ()
42 {
43 A::apply();
44 B::apply();
45 }
46
47 template< class T1 >
48 static void apply ( T1 &p1 )
49 {
50 A::apply( p1 );
51 B::apply( p1 );
52 }
53
54 template< class T1, class T2 >
55 static void apply ( T1 &p1, T2 &p2 )
56 {
57 A::apply( p1, p2 );
58 B::apply( p1, p2 );
59 }
60
61 template< class T1, class T2, class T3 >
62 static void apply ( T1 &p1, T2 &p2, T3 &p3 )
63 {
64 A::apply( p1, p2, p3 );
65 B::apply( p1, p2, p3 );
66 }
67
68 template< class T1, class T2, class T3, class T4 >
69 static void apply ( T1 &p1, T2 &p2, T3 &p3, T4 &p4 )
70 {
71 A::apply( p1, p2, p3, p4 );
72 B::apply( p1, p2, p3, p4 );
73 }
74
75 template< class T1, class T2, class T3, class T4, class T5 >
76 static void apply ( T1 &p1, T2 &p2, T3 &p3, T4 &p4, T5 &p5 )
77 {
78 A::apply( p1, p2, p3, p4, p5 );
79 B::apply( p1, p2, p3, p4, p5 );
80 }
81
82 template< class T1, class T2, class T3, class T4, class T5, class T6 >
83 static void apply ( T1 &p1, T2 &p2, T3 &p3, T4 &p4, T5 &p5, T6 &p6 )
84 {
85 A::apply( p1, p2, p3, p4, p5, p6 );
86 B::apply( p1, p2, p3, p4, p5, p6 );
87 }
88
89 template< class T1, class T2, class T3, class T4, class T5, class T6,
90 class T7 >
91 static void apply ( T1 &p1, T2 &p2, T3 &p3, T4 &p4, T5 &p5, T6 &p6,
92 T7 &p7 )
93 {
94 A::apply( p1, p2, p3, p4, p5, p6, p7 );
95 B::apply( p1, p2, p3, p4, p5, p6, p7 );
96 }
97
98 template< class T1, class T2, class T3, class T4, class T5, class T6,
99 class T7, class T8 >
100 static void apply ( T1 &p1, T2 &p2, T3 &p3, T4 &p4, T5 &p5, T6 &p6,
101 T7 &p7, T8 &p8 )
102 {
103 A::apply( p1, p2, p3, p4, p5, p6, p7, p8 );
104 B::apply( p1, p2, p3, p4, p5, p6, p7, p8 );
105 }
106
107 template< class T1, class T2, class T3, class T4, class T5, class T6,
108 class T7, class T8, class T9 >
109 static void apply ( T1 &p1, T2 &p2, T3 &p3, T4 &p4, T5 &p5, T6 &p6,
110 T7 &p7, T8 &p8, T9 &p9 )
111 {
112 A::apply( p1, p2, p3, p4, p5, p6, p7, p8, p9 );
113 B::apply( p1, p2, p3, p4, p5, p6, p7, p8, p9 );
114 }
115
116 template< class T1, class T2, class T3, class T4, class T5, class T6,
117 class T7, class T8, class T9, class T10 >
118 static void apply ( T1 &p1, T2 &p2, T3 &p3, T4 &p4, T5 &p5, T6 &p6,
119 T7 &p7, T8 &p8, T9 &p9, T10 &p10 )
120 {
121 A::apply( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 );
122 B::apply( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 );
123 }
124
125 template< class T1, class T2, class T3, class T4, class T5, class T6,
126 class T7, class T8, class T9, class T10, class T11 >
127 static void apply ( T1 &p1, T2 &p2, T3 &p3, T4 &p4, T5 &p5, T6 &p6,
128 T7 &p7, T8 &p8, T9 &p9, T10 &p10, T11 &p11 )
129 {
130 A::apply( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11 );
131 B::apply( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11 );
132 }
133
134 template< class T1, class T2, class T3, class T4, class T5, class T6,
135 class T7, class T8, class T9, class T10, class T11, class T12 >
136 static void apply ( T1 &p1, T2 &p2, T3 &p3, T4 &p4, T5 &p5, T6 &p6,
137 T7 &p7, T8 &p8, T9 &p9, T10 &p10, T11 &p11,
138 T12 &p12 )
139 {
140 A::apply( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 );
141 B::apply( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 );
142 }
143
144 template< class T1, class T2, class T3, class T4, class T5, class T6,
145 class T7, class T8, class T9, class T10, class T11, class T12,
146 class T13>
147 static void apply ( T1 &p1, T2 &p2, T3 &p3, T4 &p4, T5 &p5, T6 &p6,
148 T7 &p7, T8 &p8, T9 &p9, T10 &p10, T11 &p11,
149 T12 &p12, T13 &p13 )
150 {
151 A::apply( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13 );
152 B::apply( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13 );
153 }
154 };
155
156 } // end namespace ForLoopHelper
157
158#endif
159
160
220 template< template< int > class Operation, int first, int last >
222 : public GenericForLoop< ForLoopHelper::Apply, Operation, first, last >
223 {
224 dune_static_assert( (first <= last), "ForLoop: first > last" );
225 };
226
227}
228
229#endif // #ifndef DUNE_COMMON_FORLOOP_HH
A static loop using TMP.
Definition: forloop.hh:223
#define dune_static_assert(COND, MSG)
Helper template so that compilation fails if condition is not true.
Definition: static_assert.hh:79
Dune namespace.
Definition: alignment.hh:14
Fallback implementation of the C++0x static_assert feature.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)