mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add range check on findIndices (#1182)
- add compile-time detection of deprecated findIndex() function - replace occurrences of findIndex() with the equivalent container method
This commit is contained in:
@ -60,8 +60,7 @@ void testFind(const T& val, const ListType& lst)
|
|||||||
<<" find() = " << lst.find(val)
|
<<" find() = " << lst.find(val)
|
||||||
<<" rfind() = " << lst.rfind(val)
|
<<" rfind() = " << lst.rfind(val)
|
||||||
<<" find(2) = " << lst.find(val, 2)
|
<<" find(2) = " << lst.find(val, 2)
|
||||||
<<" rfind(2) = " << lst.rfind(val, 2)
|
<<" rfind(2) = " << lst.rfind(val, 2) << nl
|
||||||
<<" findIndex = " << findIndex(lst, val) << nl
|
|
||||||
<< nl;
|
<< nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -92,8 +92,7 @@ void testFind(const T& val, const ListType& lst)
|
|||||||
<<" find() = " << lst.find(val)
|
<<" find() = " << lst.find(val)
|
||||||
<<" rfind() = " << lst.rfind(val)
|
<<" rfind() = " << lst.rfind(val)
|
||||||
<<" find(2) = " << lst.find(val, 2)
|
<<" find(2) = " << lst.find(val, 2)
|
||||||
<<" rfind(2) = " << lst.rfind(val, 2)
|
<<" rfind(2) = " << lst.rfind(val, 2) << nl
|
||||||
<<" findIndex = " << findIndex(lst, val) << nl
|
|
||||||
<< nl;
|
<< nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,8 +50,7 @@ void testFind(const T& val, const ListType& lst)
|
|||||||
<<" find() = " << lst.find(val)
|
<<" find() = " << lst.find(val)
|
||||||
<<" rfind() = " << lst.rfind(val)
|
<<" rfind() = " << lst.rfind(val)
|
||||||
<<" find(2) = " << lst.find(val, 2)
|
<<" find(2) = " << lst.find(val, 2)
|
||||||
<<" rfind(2) = " << lst.rfind(val, 2)
|
<<" rfind(2) = " << lst.rfind(val, 2) << nl
|
||||||
<<" findIndex = " << findIndex(lst, val) << nl
|
|
||||||
<< nl;
|
<< nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -70,7 +70,7 @@ int main(int argc, char *argv[])
|
|||||||
};
|
};
|
||||||
Pout<< list2 << endl;
|
Pout<< list2 << endl;
|
||||||
|
|
||||||
Info<< findIndex(list2, vector(3, 4, 5)) << endl;
|
Info<< list2.find(vector(3, 4, 5)) << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -366,7 +366,7 @@ List<OutputIntListType> invertManyToMany
|
|||||||
// \return The index found or return -1 if not found.
|
// \return The index found or return -1 if not found.
|
||||||
// \deprecated(2017-10) - use the UList find/found methods
|
// \deprecated(2017-10) - use the UList find/found methods
|
||||||
template<class ListType>
|
template<class ListType>
|
||||||
label findIndex
|
label FOAM_DEPRECATED(2017-10) findIndex
|
||||||
(
|
(
|
||||||
const ListType& input,
|
const ListType& input,
|
||||||
typename ListType::const_reference val,
|
typename ListType::const_reference val,
|
||||||
|
|||||||
@ -740,6 +740,9 @@ Foam::labelList Foam::findIndices
|
|||||||
|
|
||||||
// Pass 1: count occurrences
|
// Pass 1: count occurrences
|
||||||
label count = 0;
|
label count = 0;
|
||||||
|
|
||||||
|
if (start >= 0)
|
||||||
|
{
|
||||||
for (label i = start; i < len; ++i)
|
for (label i = start; i < len; ++i)
|
||||||
{
|
{
|
||||||
if (input[i] == val)
|
if (input[i] == val)
|
||||||
@ -748,6 +751,7 @@ Foam::labelList Foam::findIndices
|
|||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
labelList indices(count);
|
labelList indices(count);
|
||||||
|
|
||||||
@ -761,7 +765,7 @@ Foam::labelList Foam::findIndices
|
|||||||
if (input[i] == val)
|
if (input[i] == val)
|
||||||
{
|
{
|
||||||
indices[count] = i;
|
indices[count] = i;
|
||||||
if (++count == total)
|
if (++count == total) // early termination
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,20 +97,16 @@ const
|
|||||||
{
|
{
|
||||||
return Pstream::master(comm_);
|
return Pstream::master(comm_);
|
||||||
}
|
}
|
||||||
else
|
else if (ioRanks_.size())
|
||||||
{
|
{
|
||||||
// Use any IO ranks
|
// Found myself in IO rank
|
||||||
if (ioRanks_.size())
|
return ioRanks_.found(proci);
|
||||||
{
|
|
||||||
// Find myself in IO rank
|
|
||||||
return findIndex(ioRanks_, proci) != -1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Assume all in single communicator
|
// Assume all in single communicator
|
||||||
return proci == 0;
|
return proci == 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -69,7 +69,7 @@ Foam::labelList Foam::fileOperations::hostCollatedFileOperation::subRanks
|
|||||||
IStringStream is(ioRanksString);
|
IStringStream is(ioRanksString);
|
||||||
labelList ioRanks(is);
|
labelList ioRanks(is);
|
||||||
|
|
||||||
if (findIndex(ioRanks, 0) == -1)
|
if (!ioRanks.found(0))
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Rank 0 (master) should be in the IO ranks. Currently "
|
<< "Rank 0 (master) should be in the IO ranks. Currently "
|
||||||
|
|||||||
@ -150,7 +150,7 @@ Foam::label Foam::mapNearestAMI<SourcePatch, TargetPatch>::findMappedSrcFace
|
|||||||
|
|
||||||
for (const label nbrFacei : nbrFaces)
|
for (const label nbrFacei : nbrFaces)
|
||||||
{
|
{
|
||||||
if (findIndex(visitedFaces, nbrFacei) == -1)
|
if (!visitedFaces.found(nbrFacei))
|
||||||
{
|
{
|
||||||
testFaces.append(nbrFacei);
|
testFaces.append(nbrFacei);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user