ENH: add some standard templates and macros into stdFoam.H
- some functionality similar to what the standary library <iterator> provides. * stdFoam::begin() and stdFoam::end() do type deduction, which means that many cases it is possible to manage these types of changes. For example, when managing a number of indices: Map<labelHashSet> lookup; 1) Longhand: for ( Map<labelHashSet>::const_iterator iter = lookup.begin(); iter != lookup.end(); ++iter ) { .... } 1b) The same, but wrapped via a macro: forAllConstIter(Map<labelHashSet>, lookup, iter) { .... } 2) Using stdFoam begin/end templates directly for ( auto iter = stdFoam::begin(lookup); iter != stdFoam::end(lookup); ++iter ) { .... } 2b) The same, but wrapped via a macro: forAllConstIters(lookup, iter) { .... } Note that in many cases it is possible to simply use a range-based for. Eg, labelList myList; for (auto val : myList) { ... } for (const auto& val : myList) { ... } These however will not work with any of the OpenFOAM hash-tables, since the standard C++ concept of an iterator would return a key,value pair when deferencing the *iter. The deduction methods also exhibits some slightly odd behaviour with some PtrLists (needs some more investigation).
Showing
- applications/test/DLList/Test-DLList.C 12 additions, 16 deletionsapplications/test/DLList/Test-DLList.C
- applications/test/Dictionary/Test-Dictionary.C 15 additions, 0 deletionsapplications/test/Dictionary/Test-Dictionary.C
- applications/test/HashTable/Test-hashTable.C 2 additions, 2 deletionsapplications/test/HashTable/Test-hashTable.C
- applications/test/ISLList/Test-ISLList.C 2 additions, 2 deletionsapplications/test/ISLList/Test-ISLList.C
- applications/test/NamedEnum/Test-NamedEnum.C 1 addition, 13 deletionsapplications/test/NamedEnum/Test-NamedEnum.C
- applications/test/SLList/Test-SLList.C 6 additions, 6 deletionsapplications/test/SLList/Test-SLList.C
- applications/test/labelRanges/Test-labelRanges.C 7 additions, 13 deletionsapplications/test/labelRanges/Test-labelRanges.C
- src/OpenFOAM/containers/Lists/UList/UList.H 1 addition, 63 deletionssrc/OpenFOAM/containers/Lists/UList/UList.H
- src/OpenFOAM/include/stdFoam.H 212 additions, 0 deletionssrc/OpenFOAM/include/stdFoam.H
Please register or sign in to comment