diff --git a/applications/test/FixedList/Test-FixedList.C b/applications/test/FixedList/Test-FixedList.C index 2324f54b4a..e7f4c4e7a8 100644 --- a/applications/test/FixedList/Test-FixedList.C +++ b/applications/test/FixedList/Test-FixedList.C @@ -254,8 +254,8 @@ int main(int argc, char *argv[]) Info<< "mem: " << name(list1.data()) << " " << name(list2.data()) << nl; - Swap(list1, list2); - Info<< "The Swap() function" << nl; + Foam::Swap(list1, list2); + Info<< "Foam::Swap() function" << nl; Info<< "list1: " << list1 << nl << "list2: " << list2 << nl; diff --git a/applications/test/FixedList2/Test-FixedList2.C b/applications/test/FixedList2/Test-FixedList2.C index bb8e0ad212..a9bde5224b 100644 --- a/applications/test/FixedList2/Test-FixedList2.C +++ b/applications/test/FixedList2/Test-FixedList2.C @@ -68,7 +68,7 @@ void runSwapTest for (label iLoop = 0; iLoop < nLoops; ++iLoop) { - Swap(list1, list2); + Foam::Swap(list1, list2); } Info<< "output 1: " << list1.first() << nl; diff --git a/applications/test/HashTable1/Test-HashTable1.C b/applications/test/HashTable1/Test-HashTable1.C index 1f116d0986..811e93fd65 100644 --- a/applications/test/HashTable1/Test-HashTable1.C +++ b/applications/test/HashTable1/Test-HashTable1.C @@ -366,8 +366,8 @@ int main() Info<< nl << "input values" << nl; Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl; - Info<<"global Swap function" << nl; - Swap(table1, table2); + Info<<"std::swap function" << nl; + std::swap(table1, table2); Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl; Info<<"swap method" << nl; diff --git a/applications/utilities/mesh/conversion/ensightToFoam/ensightMeshReader.C b/applications/utilities/mesh/conversion/ensightToFoam/ensightMeshReader.C index c151e94964..39c0f2e7e6 100644 --- a/applications/utilities/mesh/conversion/ensightToFoam/ensightMeshReader.C +++ b/applications/utilities/mesh/conversion/ensightToFoam/ensightMeshReader.C @@ -143,10 +143,10 @@ void Foam::fileFormats::ensightMeshReader::setHandedness // if (((x ^ y) & z) < 0) // { // // Flipped hex -// Swap(verts[0], verts[4]); -// Swap(verts[1], verts[5]); -// Swap(verts[2], verts[6]); -// Swap(verts[3], verts[7]); +// std::swap(verts[0], verts[4]); +// std::swap(verts[1], verts[5]); +// std::swap(verts[2], verts[6]); +// std::swap(verts[3], verts[7]); // } // } @@ -155,27 +155,27 @@ void Foam::fileFormats::ensightMeshReader::setHandedness if (verts.size() == 8) { // Flipped hex - Swap(verts[0], verts[4]); - Swap(verts[1], verts[5]); - Swap(verts[2], verts[6]); - Swap(verts[3], verts[7]); + std::swap(verts[0], verts[4]); + std::swap(verts[1], verts[5]); + std::swap(verts[2], verts[6]); + std::swap(verts[3], verts[7]); } else if (verts.size() == 4) { // Flipped tet. Change orientation of base - Swap(verts[0], verts[1]); + std::swap(verts[0], verts[1]); } else if (verts.size() == 5) { // Flipped pyr. Change orientation of base - Swap(verts[1], verts[3]); + std::swap(verts[1], verts[3]); } else if (verts.size() == 6) { // Flipped prism. - Swap(verts[0], verts[3]); - Swap(verts[1], verts[4]); - Swap(verts[2], verts[5]); + std::swap(verts[0], verts[3]); + std::swap(verts[1], verts[4]); + std::swap(verts[2], verts[5]); } } } diff --git a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H index 633fde0100..67160465a4 100644 --- a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H +++ b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H @@ -434,8 +434,6 @@ public: }; -// Note: uses default Foam::Swap (move construct/assignment) - // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // template @@ -451,6 +449,12 @@ Ostream& operator<<(Ostream& os, const CompactListList& list) } +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +// Does not need std::swap or Foam::Swap() specialization +// since CompactListList is MoveConstructible and MoveAssignable + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index 86563c5287..77abd3d1b5 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -465,27 +465,33 @@ Ostream& operator<<(Ostream& os, const DynamicList& list) } -// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // - -// Exchange contents of lists - see DynamicList::swap(). -template -inline void Swap(DynamicList& a, DynamicList& b) -{ - a.swap(b); -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // //- Hashing for List data template struct Hash> : List::hasher {}; +} // End namespace Foam -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +namespace Foam +{ + +//- Exchange contents of lists - see DynamicList::swap(). +// Works for lists with dissimilar SizeMin template parameters. +// If the SizeMin template parameters are identical, a regular std::swap +// works (since DynamicList is MoveConstructible and MoveAssignable) +template +inline void Swap(DynamicList& a, DynamicList& b) +{ + a.swap(b); +} } // End namespace Foam + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "DynamicListI.H" diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 4271b7b87d..ee935de25c 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -415,6 +415,7 @@ public: static constexpr unsigned max_size() noexcept { return N; } //- Swap lists by swapping the content of the individual list elements + // Essentially std::swap_ranges inline void swap(FixedList& other); @@ -547,17 +548,6 @@ template struct Hash> : FixedList::hasher {}; -// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * // - -//- Swap FixedList contents - see FixedList::swap(). -// Internally actually swaps the individual list elements -template -inline void Swap(FixedList& a, FixedList& b) -{ - a.swap(b); -} - - // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // //- Read List contents from Istream, list must have the proper size! @@ -581,6 +571,21 @@ Ostream& operator<<(Ostream& os, const FixedList& list) } // End namespace Foam +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +namespace Foam +{ + +//- Swap FixedList contents - see FixedList::swap(). +// Essentially std::swap_ranges +template +inline void Swap(FixedList& a, FixedList& b) +{ + a.swap(b); +} + +} // End namespace Foam + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index 657011ef2f..0cf3310a9b 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -374,6 +374,7 @@ inline void Foam::FixedList::swap(FixedList& other) return; // Self-swap is a no-op } + // Essentially std::swap_ranges for (unsigned i=0; i& list, const label n); template inline void reverse(UList& list); -//- Exchange contents of lists - see UList::swap(). -template -inline void Swap(UList& a, UList& b) -{ - a.swap(b); -} - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -736,6 +729,13 @@ struct sizeOp } // End namespace Foam + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +// Does not need std::swap or Foam::Swap() specialization +// since UList is MoveConstructible and MoveAssignable + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "UListI.H" diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H index 3139408d26..a10c8934d8 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H @@ -163,7 +163,11 @@ public: }; -// Note: uses default Foam::Swap (move construct/assignment) +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +// Does not need std::swap or Foam::Swap() specialization +// since SortableList is MoveConstructible and MoveAssignable + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/pointPatchFields/constraint/cyclic/cyclicPointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/constraint/cyclic/cyclicPointPatchField.C index 8cf4e9b482..ffbcb53ab3 100644 --- a/src/OpenFOAM/fields/pointPatchFields/constraint/cyclic/cyclicPointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/constraint/cyclic/cyclicPointPatchField.C @@ -154,7 +154,7 @@ void Foam::cyclicPointPatchField::swapAddSeparated { forAll(pairs, pairi) { - Swap(pf[pairs[pairi][0]], nbrPf[pairs[pairi][1]]); + Foam::Swap(pf[pairs[pairi][0]], nbrPf[pairs[pairi][1]]); } } this->addToInternalField(pField, pf); diff --git a/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C b/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C index 4160fc00d7..60aee73efc 100644 --- a/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C +++ b/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.C @@ -131,7 +131,7 @@ void Foam::DiagonalMatrix::applyPermutation(const List