STYLE: add scoping limit to Field macros

This commit is contained in:
Mark Olesen
2023-10-19 18:06:39 +02:00
parent cfa6da5953
commit 93f48d88ea
9 changed files with 119 additions and 85 deletions

View File

@ -149,10 +149,10 @@ void checkFields
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Unary Free Function : f1 OP Func f2 // Unary Free Function : f1 OP Func(f2)
#define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2) \ #define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, "f1 " #OP " " #FUNC "(f2)"); \ checkFields(f1, f2, "f1 " #OP " " #FUNC "(f2)"); \
\ \
@ -161,19 +161,20 @@ void checkFields
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop: f1 OP FUNC(f2) */ \ /* Loop: f1 OP FUNC(f2) */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP FUNC(f2P[i]); \ (f1P[i]) OP FUNC(f2P[i]); \
} \
} }
// Nullary Member Function : f1 OP f2.FUNC() // Nullary Member Function : f1 OP f2.FUNC()
#define TFOR_ALL_F_OP_F_FUNC(typeF1, f1, OP, typeF2, f2, FUNC) \ #define TFOR_ALL_F_OP_F_FUNC(typeF1, f1, OP, typeF2, f2, FUNC) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, "f1 " #OP " f2" #FUNC); \ checkFields(f1, f2, "f1 " #OP " f2" #FUNC); \
\ \
@ -182,19 +183,20 @@ void checkFields
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop: f1 OP f2.FUNC() */ \ /* Loop: f1 OP f2.FUNC() */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP (f2P[i]).FUNC(); \ (f1P[i]) OP (f2P[i]).FUNC(); \
} \
} }
// Binary Free Function : f1 OP FUNC(f2, f3) // Binary Free Function : f1 OP FUNC(f2, f3)
#define TFOR_ALL_F_OP_FUNC_F_F(typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3) \ #define TFOR_ALL_F_OP_FUNC_F_F(typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, f3, "f1 " #OP " " #FUNC "(f2, f3)"); \ checkFields(f1, f2, f3, "f1 " #OP " " #FUNC "(f2, f3)"); \
\ \
@ -204,19 +206,20 @@ void checkFields
List_CONST_ACCESS(typeF3, f3, f3P); \ List_CONST_ACCESS(typeF3, f3, f3P); \
\ \
/* Loop: f1 OP FUNC(f2, f3) */ \ /* Loop: f1 OP FUNC(f2, f3) */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP FUNC((f2P[i]), (f3P[i])); \ (f1P[i]) OP FUNC((f2P[i]), (f3P[i])); \
} \
} }
// [reduction] Binary Free Function : s OP FUNC(f1, f2) // [reduction] Binary Free Function : s OP FUNC(f1, f2)
#define TFOR_ALL_S_OP_FUNC_F_F(typeS, s, OP, FUNC, typeF1, f1, typeF2, f2) \ #define TFOR_ALL_S_OP_FUNC_F_F(typeS, s, OP, FUNC, typeF1, f1, typeF2, f2) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, "s " #OP " " #FUNC "(f1, f2)"); \ checkFields(f1, f2, "s " #OP " " #FUNC "(f1, f2)"); \
\ \
@ -225,19 +228,20 @@ void checkFields
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop: s OP FUNC(f1, f2) */ \ /* Loop: s OP FUNC(f1, f2) */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas, reduction... */ \ /* pragmas, reduction... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(s) OP FUNC((f1P[i]), (f2P[i])); \ (s) OP FUNC((f1P[i]), (f2P[i])); \
} \
} }
// Binary Free Function : f1 OP FUNC(f2, s) // Binary Free Function : f1 OP FUNC(f2, s)
#define TFOR_ALL_F_OP_FUNC_F_S(typeF1, f1, OP, FUNC, typeF2, f2, typeS, s) \ #define TFOR_ALL_F_OP_FUNC_F_S(typeF1, f1, OP, FUNC, typeF2, f2, typeS, s) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, "f1 " #OP " " #FUNC "(f2, s)"); \ checkFields(f1, f2, "f1 " #OP " " #FUNC "(f2, s)"); \
\ \
@ -246,36 +250,38 @@ void checkFields
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop: f1 OP FUNC(f2, s) */ \ /* Loop: f1 OP FUNC(f2, s) */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP FUNC((f2P[i]), (s)); \ (f1P[i]) OP FUNC((f2P[i]), (s)); \
} \
} }
// [reduction] Binary Free Function : s1 OP FUNC(f, s2) // [reduction] Binary Free Function : s1 OP FUNC(f, s2)
#define TFOR_ALL_S_OP_FUNC_F_S(typeS1, s1, OP, FUNC, typeF, f, typeS2, s2) \ #define TFOR_ALL_S_OP_FUNC_F_S(typeS1, s1, OP, FUNC, typeF, f, typeS2, s2) \
\ { \
/* Field access */ \ /* Field access */ \
List_CONST_ACCESS(typeF, f, fP); \ List_CONST_ACCESS(typeF, f, fP); \
\ \
/* Loop: s1 OP FUNC(f, s2) */ \ /* Loop: s1 OP FUNC(f, s2) */ \
const label loopLen = (f).size(); \ const label loop_len = (f).size(); \
\ \
/* pragmas, reduction... */ \ /* pragmas, reduction... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(s1) OP FUNC((fP[i]), (s2)); \ (s1) OP FUNC((fP[i]), (s2)); \
} \
} }
// Binary Free Function : f1 OP FUNC(s, f2) // Binary Free Function : f1 OP FUNC(s, f2)
#define TFOR_ALL_F_OP_FUNC_S_F(typeF1, f1, OP, FUNC, typeS, s, typeF2, f2) \ #define TFOR_ALL_F_OP_FUNC_S_F(typeF1, f1, OP, FUNC, typeS, s, typeF2, f2) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, "f1 " #OP " " #FUNC "(s, f2)"); \ checkFields(f1, f2, "f1 " #OP " " #FUNC "(s, f2)"); \
\ \
@ -284,36 +290,38 @@ void checkFields
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop: f1 OP1 f2 OP2 f3 */ \ /* Loop: f1 OP1 f2 OP2 f3 */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP FUNC((s), (f2P[i])); \ (f1P[i]) OP FUNC((s), (f2P[i])); \
} \
} }
// Binary Free Function : f1 OP FUNC(s1, s2) // Binary Free Function : f1 OP FUNC(s1, s2)
#define TFOR_ALL_F_OP_FUNC_S_S(typeF1, f1, OP, FUNC, typeS1, s1, typeS2, s2) \ #define TFOR_ALL_F_OP_FUNC_S_S(typeF1, f1, OP, FUNC, typeS1, s1, typeS2, s2) \
\ { \
/* Field access */ \ /* Field access */ \
List_ACCESS(typeF1, f1, f1P); \ List_ACCESS(typeF1, f1, f1P); \
\ \
/* Loop: f1 OP FUNC(s1, s2) */ \ /* Loop: f1 OP FUNC(s1, s2) */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP FUNC((s1), (s2)); \ (f1P[i]) OP FUNC((s1), (s2)); \
} \
} }
// Unary Member Function : f1 OP f2 FUNC(s) // Unary Member Function : f1 OP f2 FUNC(s)
#define TFOR_ALL_F_OP_F_FUNC_S(typeF1, f1, OP, typeF2, f2, FUNC, typeS, s) \ #define TFOR_ALL_F_OP_F_FUNC_S(typeF1, f1, OP, typeF2, f2, FUNC, typeS, s) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, "f1 " #OP " f2 " #FUNC "(s)"); \ checkFields(f1, f2, "f1 " #OP " f2 " #FUNC "(s)"); \
\ \
@ -322,12 +330,13 @@ void checkFields
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop: f1 OP f2 FUNC(s) */ \ /* Loop: f1 OP f2 FUNC(s) */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP (f2P[i]) FUNC((s)); \ (f1P[i]) OP (f2P[i]) FUNC((s)); \
} \
} }
@ -337,7 +346,7 @@ void checkFields
#define TFOR_ALL_F_OP_FUNC_F_F_F\ #define TFOR_ALL_F_OP_FUNC_F_F_F\
(typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3, typeF4, f4) \ (typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3, typeF4, f4) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, f3, f4, "f1 " #OP " " #FUNC "(f2, f3, f4)"); \ checkFields(f1, f2, f3, f4, "f1 " #OP " " #FUNC "(f2, f3, f4)"); \
\ \
@ -348,19 +357,20 @@ void checkFields
List_CONST_ACCESS(typeF4, f4, f4P); \ List_CONST_ACCESS(typeF4, f4, f4P); \
\ \
/* Loop: f1 OP FUNC(f2, f3, f4) */ \ /* Loop: f1 OP FUNC(f2, f3, f4) */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP FUNC((f2P[i]), (f3P[i]), (f4P[i])); \ (f1P[i]) OP FUNC((f2P[i]), (f3P[i]), (f4P[i])); \
} \
} }
// Ternary Free Function : f1 OP FUNC(f2, f3, s4) // Ternary Free Function : f1 OP FUNC(f2, f3, s4)
#define TFOR_ALL_F_OP_FUNC_F_F_S\ #define TFOR_ALL_F_OP_FUNC_F_F_S\
(typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3, typeF4, s4) \ (typeF1, f1, OP, FUNC, typeF2, f2, typeF3, f3, typeF4, s4) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, f3, "f1 " #OP " " #FUNC "(f2, f3, s)"); \ checkFields(f1, f2, f3, "f1 " #OP " " #FUNC "(f2, f3, s)"); \
\ \
@ -370,12 +380,13 @@ void checkFields
List_CONST_ACCESS(typeF3, f3, f3P); \ List_CONST_ACCESS(typeF3, f3, f3P); \
\ \
/* Loop: f1 OP FUNC(f2, f3, s4) */ \ /* Loop: f1 OP FUNC(f2, f3, s4) */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP FUNC((f2P[i]), (f3P[i]), (s4)); \ (f1P[i]) OP FUNC((f2P[i]), (f3P[i]), (s4)); \
} \
} }
@ -384,7 +395,7 @@ void checkFields
// Member operator : this field f1 OP1 f2 OP2 f3 // Member operator : this field f1 OP1 f2 OP2 f3
#define TFOR_ALL_F_OP_F_OP_F(typeF1, f1, OP1, typeF2, f2, OP2, typeF3, f3) \ #define TFOR_ALL_F_OP_F_OP_F(typeF1, f1, OP1, typeF2, f2, OP2, typeF3, f3) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, f3, "f1 " #OP1 " f2 " #OP2 " f3"); \ checkFields(f1, f2, f3, "f1 " #OP1 " f2 " #OP2 " f3"); \
\ \
@ -394,19 +405,20 @@ void checkFields
List_CONST_ACCESS(typeF3, f3, f3P); \ List_CONST_ACCESS(typeF3, f3, f3P); \
\ \
/* Loop: f1 OP1 f2 OP2 f3 */ \ /* Loop: f1 OP1 f2 OP2 f3 */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP1 (f2P[i]) OP2 (f3P[i]); \ (f1P[i]) OP1 (f2P[i]) OP2 (f3P[i]); \
} \
} }
// Member operator : this field f1 OP1 s OP2 f2 // Member operator : this field f1 OP1 s OP2 f2
#define TFOR_ALL_F_OP_S_OP_F(typeF1, f1, OP1, typeS, s, OP2, typeF2, f2) \ #define TFOR_ALL_F_OP_S_OP_F(typeF1, f1, OP1, typeS, s, OP2, typeF2, f2) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, "f1 " #OP1 " s " #OP2 " f2"); \ checkFields(f1, f2, "f1 " #OP1 " s " #OP2 " f2"); \
\ \
@ -415,19 +427,20 @@ void checkFields
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop: f1 OP1 s OP2 f2 */ \ /* Loop: f1 OP1 s OP2 f2 */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP1 (s) OP2 (f2P[i]); \ (f1P[i]) OP1 (s) OP2 (f2P[i]); \
} \
} }
// Member operator : this field f1 OP1 f2 OP2 s // Member operator : this field f1 OP1 f2 OP2 s
#define TFOR_ALL_F_OP_F_OP_S(typeF1, f1, OP1, typeF2, f2, OP2, typeS, s) \ #define TFOR_ALL_F_OP_F_OP_S(typeF1, f1, OP1, typeF2, f2, OP2, typeS, s) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, "f1 " #OP1 " f2 " #OP2 " s"); \ checkFields(f1, f2, "f1 " #OP1 " f2 " #OP2 " s"); \
\ \
@ -436,19 +449,20 @@ void checkFields
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop f1 OP1 s OP2 f2 */ \ /* Loop f1 OP1 s OP2 f2 */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP1 (f2P[i]) OP2 (s); \ (f1P[i]) OP1 (f2P[i]) OP2 (s); \
} \
} }
// Member operator : this field f1 OP f2 // Member operator : this field f1 OP f2
#define TFOR_ALL_F_OP_F(typeF1, f1, OP, typeF2, f2) \ #define TFOR_ALL_F_OP_F(typeF1, f1, OP, typeF2, f2) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, "f1 " #OP " f2"); \ checkFields(f1, f2, "f1 " #OP " f2"); \
\ \
@ -457,19 +471,20 @@ void checkFields
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop: f1 OP f2 */ \ /* Loop: f1 OP f2 */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP (f2P[i]); \ (f1P[i]) OP (f2P[i]); \
} \
} }
// Member operator : this field f1 OP1 OP2 f2 // Member operator : this field f1 OP1 OP2 f2
#define TFOR_ALL_F_OP_OP_F(typeF1, f1, OP1, OP2, typeF2, f2) \ #define TFOR_ALL_F_OP_OP_F(typeF1, f1, OP1, OP2, typeF2, f2) \
\ { \
/* Check fields have same size */ \ /* Check fields have same size */ \
checkFields(f1, f2, #OP1 " " #OP2 " f2"); \ checkFields(f1, f2, #OP1 " " #OP2 " f2"); \
\ \
@ -478,29 +493,31 @@ void checkFields
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop: f1 OP1 OP2 f2 */ \ /* Loop: f1 OP1 OP2 f2 */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(f1P[i]) OP1 OP2 (f2P[i]); \ (f1P[i]) OP1 OP2 (f2P[i]); \
} \
} }
// Member operator : this field f OP s // Member operator : this field f OP s
#define TFOR_ALL_F_OP_S(typeF, f, OP, typeS, s) \ #define TFOR_ALL_F_OP_S(typeF, f, OP, typeS, s) \
\ { \
/* Field access */ \ /* Field access */ \
List_ACCESS(typeF, f, fP); \ List_ACCESS(typeF, f, fP); \
\ \
/* Loop: f OP s */ \ /* Loop: f OP s */ \
const label loopLen = (f).size(); \ const label loop_len = (f).size(); \
\ \
/* pragmas... */ \ /* pragmas... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(fP[i]) OP (s); \ (fP[i]) OP (s); \
} \
} }
@ -509,52 +526,54 @@ void checkFields
// Friend operator function : s OP f, allocates storage for s // Friend operator function : s OP f, allocates storage for s
#define TFOR_ALL_S_OP_F(typeS, s, OP, typeF, f) \ #define TFOR_ALL_S_OP_F(typeS, s, OP, typeF, f) \
\ { \
/* Field access */ \ /* Field access */ \
List_CONST_ACCESS(typeF, f, fP); \ List_CONST_ACCESS(typeF, f, fP); \
\ \
/* Loop: s OP f */ \ /* Loop: s OP f */ \
const label loopLen = (f).size(); \ const label loop_len = (f).size(); \
\ \
/* pragmas, reduction... */ \ /* pragmas, reduction... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(s) OP (fP[i]); \ (s) OP (fP[i]); \
} \
} }
// Friend operator function : s OP1 f1 OP2 f2, allocates storage for s // Friend operator function : s OP1 f1 OP2 f2, allocates storage for s
#define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2) \ #define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2) \
\ { \
/* Field access */ \ /* Field access */ \
List_CONST_ACCESS(typeF1, f1, f1P); \ List_CONST_ACCESS(typeF1, f1, f1P); \
List_CONST_ACCESS(typeF2, f2, f2P); \ List_CONST_ACCESS(typeF2, f2, f2P); \
\ \
/* Loop: s OP1 f1 OP2 f2 */ \ /* Loop: s OP1 f1 OP2 f2 */ \
const label loopLen = (f1).size(); \ const label loop_len = (f1).size(); \
\ \
/* pragmas, reduction... */ \ /* pragmas, reduction... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(s) OP1 (f1P[i]) OP2 (f2P[i]); \ (s) OP1 (f1P[i]) OP2 (f2P[i]); \
} \
} }
// Friend operator function : s OP FUNC(f), allocates storage for s // Friend operator function : s OP FUNC(f), allocates storage for s
#define TFOR_ALL_S_OP_FUNC_F(typeS, s, OP, FUNC, typeF, f) \ #define TFOR_ALL_S_OP_FUNC_F(typeS, s, OP, FUNC, typeF, f) \
\ { \
/* Field access */ \ /* Field access */ \
List_CONST_ACCESS(typeF, f, fP); \ List_CONST_ACCESS(typeF, f, fP); \
\ \
/* Loop: s OP FUNC(f) */ \ /* Loop: s OP FUNC(f) */ \
const label loopLen = (f).size(); \ const label loop_len = (f).size(); \
\ \
/* pragmas, reduction... */ \ /* pragmas, reduction... */ \
for (label i = 0; i < loopLen; ++i) \ for (label i = 0; i < loop_len; ++i) \
{ \ { \
(s) OP FUNC(fP[i]); \ (s) OP FUNC(fP[i]); \
} \
} }

View File

@ -44,6 +44,7 @@ namespace Foam
template<> template<>
void boolField::negate() void boolField::negate()
{ {
// std::for_each, std::logical_not
TFOR_ALL_F_OP_OP_F(bool, *this, =, !, bool, *this) TFOR_ALL_F_OP_OP_F(bool, *this, =, !, bool, *this)
} }

View File

@ -251,9 +251,10 @@ namespace Foam
template<> template<>
complex sumProd(const UList<complex>& f1, const UList<complex>& f2) complex sumProd(const UList<complex>& f1, const UList<complex>& f2)
{ {
complex result = Zero; complex result(0);
if (f1.size() && (f1.size() == f2.size())) if (f1.size() && (f1.size() == f2.size()))
{ {
// std::inner_product
TFOR_ALL_S_OP_F_OP_F(complex, result, +=, complex, f1, *, complex, f2) TFOR_ALL_S_OP_F_OP_F(complex, result, +=, complex, f1, *, complex, f2)
} }
return result; return result;

View File

@ -68,6 +68,7 @@ void scalarField::replace(const direction, const scalar& s)
void stabilise(scalarField& res, const UList<scalar>& sf, const scalar s) void stabilise(scalarField& res, const UList<scalar>& sf, const scalar s)
{ {
// std::transform
TFOR_ALL_F_OP_FUNC_S_F TFOR_ALL_F_OP_FUNC_S_F
( (
scalar, res, =, ::Foam::stabilise, scalar, s, scalar, sf scalar, res, =, ::Foam::stabilise, scalar, s, scalar, sf
@ -98,6 +99,7 @@ float sumProd(const UList<float>& f1, const UList<float>& f2)
float result = 0.0; float result = 0.0;
if (f1.size() && (f1.size() == f2.size())) if (f1.size() && (f1.size() == f2.size()))
{ {
// std::inner_product
TFOR_ALL_S_OP_F_OP_F(float, result, +=, float, f1, *, float, f2) TFOR_ALL_S_OP_F_OP_F(float, result, +=, float, f1, *, float, f2)
} }
return result; return result;
@ -110,6 +112,7 @@ double sumProd(const UList<double>& f1, const UList<double>& f2)
double result = 0.0; double result = 0.0;
if (f1.size() && (f1.size() == f2.size())) if (f1.size() && (f1.size() == f2.size()))
{ {
// std::inner_product
TFOR_ALL_S_OP_F_OP_F(double, result, +=, double, f1, *, double, f2) TFOR_ALL_S_OP_F_OP_F(double, result, +=, double, f1, *, double, f2)
} }
return result; return result;

View File

@ -54,6 +54,7 @@ UNARY_FUNCTION(symmTensor, symmTensor, cof)
void inv(Field<symmTensor>& result, const UList<symmTensor>& f1) void inv(Field<symmTensor>& result, const UList<symmTensor>& f1)
{ {
// With 'failsafe' invert // With 'failsafe' invert
// std::transform
TFOR_ALL_F_OP_F_FUNC(symmTensor, result, =, symmTensor, f1, safeInv) TFOR_ALL_F_OP_F_FUNC(symmTensor, result, =, symmTensor, f1, safeInv)
} }

View File

@ -39,6 +39,7 @@ void Foam::transform
const Field<Type>& fld const Field<Type>& fld
) )
{ {
// std::transform
TFOR_ALL_F_OP_FUNC_S_F TFOR_ALL_F_OP_FUNC_S_F
( (
Type, result, =, transform, symmTensor, rot, Type, fld Type, result, =, transform, symmTensor, rot, Type, fld
@ -59,6 +60,7 @@ void Foam::transform
return transform(result, rot.front(), fld); return transform(result, rot.front(), fld);
} }
// std::transform
TFOR_ALL_F_OP_FUNC_F_F TFOR_ALL_F_OP_FUNC_F_F
( (
Type, result, =, transform, symmTensor, rot, Type, fld Type, result, =, transform, symmTensor, rot, Type, fld

View File

@ -55,6 +55,7 @@ UNARY_FUNCTION(tensor, tensor, cof)
void inv(Field<tensor>& result, const UList<tensor>& f1) void inv(Field<tensor>& result, const UList<tensor>& f1)
{ {
// With 'failsafe' invert // With 'failsafe' invert
// std::transform
TFOR_ALL_F_OP_F_FUNC(tensor, result, =, tensor, f1, safeInv) TFOR_ALL_F_OP_F_FUNC(tensor, result, =, tensor, f1, safeInv)
} }

View File

@ -39,7 +39,8 @@ void Foam::transform
const vectorField& tf const vectorField& tf
) )
{ {
tensor rot = q.R(); const tensor rot = q.R();
// std::transform
TFOR_ALL_F_OP_FUNC_S_F(vector, rtf, =, transform, tensor, rot, vector, tf) TFOR_ALL_F_OP_FUNC_S_F(vector, rtf, =, transform, tensor, rot, vector, tf)
} }
@ -76,11 +77,12 @@ void Foam::transformPoints
const vectorField& fld const vectorField& fld
) )
{ {
vector trans = tr.t(); const vector trans = tr.t();
// Check if any translation // Check if any translation
if (mag(trans) > VSMALL) if (mag(trans) > VSMALL)
{ {
// std::transform
TFOR_ALL_F_OP_F_OP_S(vector, result, =, vector, fld, -, vector, trans); TFOR_ALL_F_OP_F_OP_S(vector, result, =, vector, fld, -, vector, trans);
} }
else else

View File

@ -39,6 +39,7 @@ void Foam::transform
const Field<Type>& fld const Field<Type>& fld
) )
{ {
// std::transform
TFOR_ALL_F_OP_FUNC_S_F TFOR_ALL_F_OP_FUNC_S_F
( (
Type, result, =, transform, tensor, rot, Type, fld Type, result, =, transform, tensor, rot, Type, fld
@ -59,6 +60,7 @@ void Foam::transform
return transform(result, rot.front(), fld); return transform(result, rot.front(), fld);
} }
// std::transform
TFOR_ALL_F_OP_FUNC_F_F TFOR_ALL_F_OP_FUNC_F_F
( (
Type, result, =, transform, tensor, rot, Type, fld Type, result, =, transform, tensor, rot, Type, fld
@ -163,6 +165,7 @@ void Foam::invTransform
const Field<Type>& fld const Field<Type>& fld
) )
{ {
// std::transform
TFOR_ALL_F_OP_FUNC_S_F TFOR_ALL_F_OP_FUNC_S_F
( (
Type, result, =, invTransform, tensor, rot, Type, fld Type, result, =, invTransform, tensor, rot, Type, fld
@ -183,6 +186,7 @@ void Foam::invTransform
return invTransform(result, rot.front(), fld); return invTransform(result, rot.front(), fld);
} }
// std::transform
TFOR_ALL_F_OP_FUNC_F_F TFOR_ALL_F_OP_FUNC_F_F
( (
Type, result, =, invTransform, tensor, rot, Type, fld Type, result, =, invTransform, tensor, rot, Type, fld