STYLE: qualify Swap with Foam:: prefix (visibility)

- drop unnecessary Foam::Swap specializations when MoveConstructible
  and MoveAssignable already apply. The explicit redirect to swap
  member functions was needed before proper move semantics where
  added.

  Removed specializations: autoPtr, refPtr, tmp, UList.
  Retained specialization: DynamicList, FixedList.

     Special handling for DynamicList is only to accommodate dissimilar
     sizing template parameters (which probably doesn't occur in
     practice).
     Special handling for FixedList to apply element-wise swapping.

- use std::swap for primitives. No need to mask with Foam::Swap wrapper
This commit is contained in:
Mark Olesen 2023-08-11 13:25:51 +02:00
parent fabd3f4e0c
commit eeb9d144e3
22 changed files with 94 additions and 88 deletions

View File

@ -254,8 +254,8 @@ int main(int argc, char *argv[])
Info<< "mem: " Info<< "mem: "
<< name(list1.data()) << " " << name(list2.data()) << nl; << name(list1.data()) << " " << name(list2.data()) << nl;
Swap(list1, list2); Foam::Swap(list1, list2);
Info<< "The Swap() function" << nl; Info<< "Foam::Swap() function" << nl;
Info<< "list1: " << list1 << nl Info<< "list1: " << list1 << nl
<< "list2: " << list2 << nl; << "list2: " << list2 << nl;

View File

@ -68,7 +68,7 @@ void runSwapTest
for (label iLoop = 0; iLoop < nLoops; ++iLoop) for (label iLoop = 0; iLoop < nLoops; ++iLoop)
{ {
Swap(list1, list2); Foam::Swap(list1, list2);
} }
Info<< "output 1: " << list1.first() << nl; Info<< "output 1: " << list1.first() << nl;

View File

@ -366,8 +366,8 @@ int main()
Info<< nl << "input values" << nl; Info<< nl << "input values" << nl;
Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl; Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl;
Info<<"global Swap function" << nl; Info<<"std::swap function" << nl;
Swap(table1, table2); std::swap(table1, table2);
Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl; Info<<"table1 = " << table1 << nl <<"table2 = " << table2 << nl;
Info<<"swap method" << nl; Info<<"swap method" << nl;

View File

@ -143,10 +143,10 @@ void Foam::fileFormats::ensightMeshReader::setHandedness
// if (((x ^ y) & z) < 0) // if (((x ^ y) & z) < 0)
// { // {
// // Flipped hex // // Flipped hex
// Swap(verts[0], verts[4]); // std::swap(verts[0], verts[4]);
// Swap(verts[1], verts[5]); // std::swap(verts[1], verts[5]);
// Swap(verts[2], verts[6]); // std::swap(verts[2], verts[6]);
// Swap(verts[3], verts[7]); // std::swap(verts[3], verts[7]);
// } // }
// } // }
@ -155,27 +155,27 @@ void Foam::fileFormats::ensightMeshReader::setHandedness
if (verts.size() == 8) if (verts.size() == 8)
{ {
// Flipped hex // Flipped hex
Swap(verts[0], verts[4]); std::swap(verts[0], verts[4]);
Swap(verts[1], verts[5]); std::swap(verts[1], verts[5]);
Swap(verts[2], verts[6]); std::swap(verts[2], verts[6]);
Swap(verts[3], verts[7]); std::swap(verts[3], verts[7]);
} }
else if (verts.size() == 4) else if (verts.size() == 4)
{ {
// Flipped tet. Change orientation of base // Flipped tet. Change orientation of base
Swap(verts[0], verts[1]); std::swap(verts[0], verts[1]);
} }
else if (verts.size() == 5) else if (verts.size() == 5)
{ {
// Flipped pyr. Change orientation of base // Flipped pyr. Change orientation of base
Swap(verts[1], verts[3]); std::swap(verts[1], verts[3]);
} }
else if (verts.size() == 6) else if (verts.size() == 6)
{ {
// Flipped prism. // Flipped prism.
Swap(verts[0], verts[3]); std::swap(verts[0], verts[3]);
Swap(verts[1], verts[4]); std::swap(verts[1], verts[4]);
Swap(verts[2], verts[5]); std::swap(verts[2], verts[5]);
} }
} }
} }

View File

@ -434,8 +434,6 @@ public:
}; };
// Note: uses default Foam::Swap (move construct/assignment)
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T> template<class T>
@ -451,6 +449,12 @@ Ostream& operator<<(Ostream& os, const CompactListList<T>& list)
} }
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
// Does not need std::swap or Foam::Swap() specialization
// since CompactListList is MoveConstructible and MoveAssignable
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -465,27 +465,33 @@ Ostream& operator<<(Ostream& os, const DynamicList<T, SizeMin>& list)
} }
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
// Exchange contents of lists - see DynamicList::swap().
template<class T, int SizeMinA, int SizeMinB>
inline void Swap(DynamicList<T, SizeMinA>& a, DynamicList<T, SizeMinB>& b)
{
a.swap(b);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Hashing for List data //- Hashing for List data
template<class T, int SizeMin> template<class T, int SizeMin>
struct Hash<DynamicList<T, SizeMin>> : List<T>::hasher {}; struct Hash<DynamicList<T, SizeMin>> : List<T>::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<class T, int SizeMinA, int SizeMinB>
inline void Swap(DynamicList<T, SizeMinA>& a, DynamicList<T, SizeMinB>& b)
{
a.swap(b);
}
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "DynamicListI.H" #include "DynamicListI.H"

View File

@ -415,6 +415,7 @@ public:
static constexpr unsigned max_size() noexcept { return N; } static constexpr unsigned max_size() noexcept { return N; }
//- Swap lists by swapping the content of the individual list elements //- Swap lists by swapping the content of the individual list elements
// Essentially std::swap_ranges
inline void swap(FixedList<T, N>& other); inline void swap(FixedList<T, N>& other);
@ -547,17 +548,6 @@ template<class T, unsigned N>
struct Hash<FixedList<T, N>> : FixedList<T, N>::hasher {}; struct Hash<FixedList<T, N>> : FixedList<T, N>::hasher {};
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
//- Swap FixedList contents - see FixedList::swap().
// Internally actually swaps the individual list elements
template<class T, unsigned N>
inline void Swap(FixedList<T, N>& a, FixedList<T, N>& b)
{
a.swap(b);
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
//- Read List contents from Istream, list must have the proper size! //- Read List contents from Istream, list must have the proper size!
@ -581,6 +571,21 @@ Ostream& operator<<(Ostream& os, const FixedList<T, N>& list)
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
namespace Foam
{
//- Swap FixedList contents - see FixedList::swap().
// Essentially std::swap_ranges
template<class T, unsigned N>
inline void Swap(FixedList<T, N>& a, FixedList<T, N>& b)
{
a.swap(b);
}
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -374,6 +374,7 @@ inline void Foam::FixedList<T, N>::swap(FixedList<T, N>& other)
return; // Self-swap is a no-op return; // Self-swap is a no-op
} }
// Essentially std::swap_ranges
for (unsigned i=0; i<N; ++i) for (unsigned i=0; i<N; ++i)
{ {
Foam::Swap(v_[i], other.v_[i]); Foam::Swap(v_[i], other.v_[i]);

View File

@ -692,13 +692,6 @@ inline void reverse(UList<T>& list, const label n);
template<class T> template<class T>
inline void reverse(UList<T>& list); inline void reverse(UList<T>& list);
//- Exchange contents of lists - see UList::swap().
template<class T>
inline void Swap(UList<T>& a, UList<T>& b)
{
a.swap(b);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -736,6 +729,13 @@ struct sizeOp
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
// Does not need std::swap or Foam::Swap() specialization
// since UList is MoveConstructible and MoveAssignable
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "UListI.H" #include "UListI.H"

View File

@ -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
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -154,7 +154,7 @@ void Foam::cyclicPointPatchField<Type>::swapAddSeparated
{ {
forAll(pairs, pairi) 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); this->addToInternalField(pField, pf);

View File

@ -131,7 +131,7 @@ void Foam::DiagonalMatrix<Type>::applyPermutation(const List<label>& p)
label j = p[i]; label j = p[i];
while (i != j) while (i != j)
{ {
Swap((*this)[prev], (*this)[j]); Foam::Swap((*this)[prev], (*this)[j]);
pass[j] = true; pass[j] = true;
prev = j; prev = j;
j = p[j]; j = p[j];

View File

@ -165,8 +165,8 @@ void Foam::QRMatrix<MatrixType>::decompose
AT.subRow(k) = R2; AT.subRow(k) = R2;
AT.subRow(maxNormi + k) = R1; AT.subRow(maxNormi + k) = R1;
Swap(p_[k], p_[maxNormi + k]); std::swap(p_[k], p_[maxNormi + k]);
Swap(norms[k], norms[maxNormi + k]); std::swap(norms[k], norms[maxNormi + k]);
} }
{ {

View File

@ -143,7 +143,11 @@ bool Foam::manualGAMGProcAgglomeration::agglomerate()
// This is my cluster. Make sure master index is // This is my cluster. Make sure master index is
// first // first
agglomProcIDs = cluster; agglomProcIDs = cluster;
Swap(agglomProcIDs[0], agglomProcIDs[masterIndex]); std::swap
(
agglomProcIDs[0],
agglomProcIDs[masterIndex]
);
} }
} }

View File

@ -122,7 +122,7 @@ void Foam::LUDecompose
for (label k = 0; k < m; ++k) for (label k = 0; k < m; ++k)
{ {
Swap(matrixj[k], matrixiMax[k]); std::swap(matrixj[k], matrixiMax[k]);
} }
sign *= -1; sign *= -1;

View File

@ -59,9 +59,9 @@ void Foam::solve
{ {
for (label k = i; k < m; ++k) for (label k = i; k < m; ++k)
{ {
Swap(tmpMatrix(i, k), tmpMatrix(iMax, k)); Foam::Swap(tmpMatrix(i, k), tmpMatrix(iMax, k));
} }
Swap(sourceSol[i], sourceSol[iMax]); Foam::Swap(sourceSol[i], sourceSol[iMax]);
} }
// Check that the system of equations isn't singular // Check that the system of equations isn't singular

View File

@ -333,16 +333,10 @@ public:
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
// Global Functions // Does not need std::swap or Foam::Swap() specialization
// since autoPtr is MoveConstructible and MoveAssignable
//- Specializes the Swap algorithm for autoPtr (swaps pointers).
template<class T>
void Swap(autoPtr<T>& lhs, autoPtr<T>& rhs)
{
lhs.swap(rhs);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -366,16 +366,10 @@ public:
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
// Global Functions // Does not need std::swap or Foam::Swap() specialization
// since refPtr is MoveConstructible and MoveAssignable
//- Specializes the Swap algorithm for refPtr (swaps pointers and types).
template<class T>
void Swap(refPtr<T>& lhs, refPtr<T>& rhs)
{
lhs.swap(rhs);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -372,16 +372,10 @@ public:
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
// Global Functions // Does not need std::swap or Foam::Swap() specialization
// since tmp is MoveConstructible and MoveAssignable
//- Specializes the Swap algorithm for tmp (swaps pointers and types).
template<class T>
void Swap(tmp<T>& lhs, tmp<T>& rhs)
{
lhs.swap(rhs);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -269,7 +269,7 @@ inline FixedList<Type, 6> tetCutPrism23
FixedList<Type, 6> result = tetCutPrism01(x, f); FixedList<Type, 6> result = tetCutPrism01(x, f);
result[0] = x[2]; result[0] = x[2];
result[3] = x[3]; result[3] = x[3];
Swap(result[2], result[4]); std::swap(result[2], result[4]);
return result; return result;
} }

View File

@ -134,7 +134,7 @@ Foam::Vector2D<Foam::complex> Foam::eigenValues(const tensor2D& T)
// Sort the eigenvalues into ascending order // Sort the eigenvalues into ascending order
if (eVals.x().real() > eVals.y().real()) if (eVals.x().real() > eVals.y().real())
{ {
Swap(eVals.x(), eVals.y()); std::swap(eVals.x(), eVals.y());
} }
return eVals; return eVals;

View File

@ -2894,7 +2894,7 @@ void Foam::polyMeshAdder::add
bool flip = zoneFlip[facei]; bool flip = zoneFlip[facei];
if (newNei < newOwn) if (newNei < newOwn)
{ {
Swap(newOwn, newNei); std::swap(newOwn, newNei);
newFace = newFace.reverseFace(); newFace = newFace.reverseFace();
flipFaceFlux = !flipFaceFlux; flipFaceFlux = !flipFaceFlux;
flip = !flip; flip = !flip;