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:
parent
fabd3f4e0c
commit
eeb9d144e3
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -434,8 +434,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// Note: uses default Foam::Swap (move construct/assignment)
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
template<class T, int SizeMin>
|
||||
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
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "DynamicListI.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<T, N>& other);
|
||||
|
||||
|
||||
@ -547,17 +548,6 @@ template<class T, unsigned N>
|
||||
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 * * * * * * * * * * * * //
|
||||
|
||||
//- 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
|
||||
|
||||
// * * * * * * * * * * * * * * * 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
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
@ -374,6 +374,7 @@ inline void Foam::FixedList<T, N>::swap(FixedList<T, N>& other)
|
||||
return; // Self-swap is a no-op
|
||||
}
|
||||
|
||||
// Essentially std::swap_ranges
|
||||
for (unsigned i=0; i<N; ++i)
|
||||
{
|
||||
Foam::Swap(v_[i], other.v_[i]);
|
||||
|
@ -692,13 +692,6 @@ inline void reverse(UList<T>& list, const label n);
|
||||
template<class T>
|
||||
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
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Does not need std::swap or Foam::Swap() specialization
|
||||
// since UList is MoveConstructible and MoveAssignable
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "UListI.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
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
@ -154,7 +154,7 @@ void Foam::cyclicPointPatchField<Type>::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);
|
||||
|
@ -131,7 +131,7 @@ void Foam::DiagonalMatrix<Type>::applyPermutation(const List<label>& p)
|
||||
label j = p[i];
|
||||
while (i != j)
|
||||
{
|
||||
Swap((*this)[prev], (*this)[j]);
|
||||
Foam::Swap((*this)[prev], (*this)[j]);
|
||||
pass[j] = true;
|
||||
prev = j;
|
||||
j = p[j];
|
||||
|
@ -165,8 +165,8 @@ void Foam::QRMatrix<MatrixType>::decompose
|
||||
AT.subRow(k) = R2;
|
||||
AT.subRow(maxNormi + k) = R1;
|
||||
|
||||
Swap(p_[k], p_[maxNormi + k]);
|
||||
Swap(norms[k], norms[maxNormi + k]);
|
||||
std::swap(p_[k], p_[maxNormi + k]);
|
||||
std::swap(norms[k], norms[maxNormi + k]);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -143,7 +143,11 @@ bool Foam::manualGAMGProcAgglomeration::agglomerate()
|
||||
// This is my cluster. Make sure master index is
|
||||
// first
|
||||
agglomProcIDs = cluster;
|
||||
Swap(agglomProcIDs[0], agglomProcIDs[masterIndex]);
|
||||
std::swap
|
||||
(
|
||||
agglomProcIDs[0],
|
||||
agglomProcIDs[masterIndex]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ void Foam::LUDecompose
|
||||
|
||||
for (label k = 0; k < m; ++k)
|
||||
{
|
||||
Swap(matrixj[k], matrixiMax[k]);
|
||||
std::swap(matrixj[k], matrixiMax[k]);
|
||||
}
|
||||
|
||||
sign *= -1;
|
||||
|
@ -59,9 +59,9 @@ void Foam::solve
|
||||
{
|
||||
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
|
||||
|
@ -333,16 +333,10 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Global Functions
|
||||
|
||||
//- Specializes the Swap algorithm for autoPtr (swaps pointers).
|
||||
template<class T>
|
||||
void Swap(autoPtr<T>& lhs, autoPtr<T>& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
// Does not need std::swap or Foam::Swap() specialization
|
||||
// since autoPtr is MoveConstructible and MoveAssignable
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
@ -366,16 +366,10 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Global Functions
|
||||
|
||||
//- Specializes the Swap algorithm for refPtr (swaps pointers and types).
|
||||
template<class T>
|
||||
void Swap(refPtr<T>& lhs, refPtr<T>& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
// Does not need std::swap or Foam::Swap() specialization
|
||||
// since refPtr is MoveConstructible and MoveAssignable
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
@ -372,16 +372,10 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Global Functions
|
||||
|
||||
//- Specializes the Swap algorithm for tmp (swaps pointers and types).
|
||||
template<class T>
|
||||
void Swap(tmp<T>& lhs, tmp<T>& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
// Does not need std::swap or Foam::Swap() specialization
|
||||
// since tmp is MoveConstructible and MoveAssignable
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
@ -269,7 +269,7 @@ inline FixedList<Type, 6> tetCutPrism23
|
||||
FixedList<Type, 6> result = tetCutPrism01(x, f);
|
||||
result[0] = x[2];
|
||||
result[3] = x[3];
|
||||
Swap(result[2], result[4]);
|
||||
std::swap(result[2], result[4]);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ Foam::Vector2D<Foam::complex> Foam::eigenValues(const tensor2D& T)
|
||||
// Sort the eigenvalues into ascending order
|
||||
if (eVals.x().real() > eVals.y().real())
|
||||
{
|
||||
Swap(eVals.x(), eVals.y());
|
||||
std::swap(eVals.x(), eVals.y());
|
||||
}
|
||||
|
||||
return eVals;
|
||||
|
@ -2894,7 +2894,7 @@ void Foam::polyMeshAdder::add
|
||||
bool flip = zoneFlip[facei];
|
||||
if (newNei < newOwn)
|
||||
{
|
||||
Swap(newOwn, newNei);
|
||||
std::swap(newOwn, newNei);
|
||||
newFace = newFace.reverseFace();
|
||||
flipFaceFlux = !flipFaceFlux;
|
||||
flip = !flip;
|
||||
|
Loading…
Reference in New Issue
Block a user