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)
|
||||
<<" rfind() = " << lst.rfind(val)
|
||||
<<" find(2) = " << lst.find(val, 2)
|
||||
<<" rfind(2) = " << lst.rfind(val, 2)
|
||||
<<" findIndex = " << findIndex(lst, val) << nl
|
||||
<<" rfind(2) = " << lst.rfind(val, 2) << nl
|
||||
<< nl;
|
||||
}
|
||||
|
||||
|
||||
@ -92,8 +92,7 @@ void testFind(const T& val, const ListType& lst)
|
||||
<<" find() = " << lst.find(val)
|
||||
<<" rfind() = " << lst.rfind(val)
|
||||
<<" find(2) = " << lst.find(val, 2)
|
||||
<<" rfind(2) = " << lst.rfind(val, 2)
|
||||
<<" findIndex = " << findIndex(lst, val) << nl
|
||||
<<" rfind(2) = " << lst.rfind(val, 2) << nl
|
||||
<< nl;
|
||||
}
|
||||
|
||||
|
||||
@ -50,8 +50,7 @@ void testFind(const T& val, const ListType& lst)
|
||||
<<" find() = " << lst.find(val)
|
||||
<<" rfind() = " << lst.rfind(val)
|
||||
<<" find(2) = " << lst.find(val, 2)
|
||||
<<" rfind(2) = " << lst.rfind(val, 2)
|
||||
<<" findIndex = " << findIndex(lst, val) << nl
|
||||
<<" rfind(2) = " << lst.rfind(val, 2) << nl
|
||||
<< nl;
|
||||
}
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ int main(int argc, char *argv[])
|
||||
};
|
||||
Pout<< list2 << endl;
|
||||
|
||||
Info<< findIndex(list2, vector(3, 4, 5)) << endl;
|
||||
Info<< list2.find(vector(3, 4, 5)) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / 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
|
||||
This file is part of OpenFOAM.
|
||||
@ -366,7 +366,7 @@ List<OutputIntListType> invertManyToMany
|
||||
// \return The index found or return -1 if not found.
|
||||
// \deprecated(2017-10) - use the UList find/found methods
|
||||
template<class ListType>
|
||||
label findIndex
|
||||
label FOAM_DEPRECATED(2017-10) findIndex
|
||||
(
|
||||
const ListType& input,
|
||||
typename ListType::const_reference val,
|
||||
|
||||
@ -740,12 +740,16 @@ Foam::labelList Foam::findIndices
|
||||
|
||||
// Pass 1: count occurrences
|
||||
label count = 0;
|
||||
for (label i = start; i < len; ++i)
|
||||
|
||||
if (start >= 0)
|
||||
{
|
||||
if (input[i] == val)
|
||||
for (label i = start; i < len; ++i)
|
||||
{
|
||||
if (!count) start = i; // adjust start for second pass
|
||||
++count;
|
||||
if (input[i] == val)
|
||||
{
|
||||
if (!count) start = i; // adjust start for second pass
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -761,7 +765,7 @@ Foam::labelList Foam::findIndices
|
||||
if (input[i] == val)
|
||||
{
|
||||
indices[count] = i;
|
||||
if (++count == total)
|
||||
if (++count == total) // early termination
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@ -97,19 +97,15 @@ const
|
||||
{
|
||||
return Pstream::master(comm_);
|
||||
}
|
||||
else if (ioRanks_.size())
|
||||
{
|
||||
// Found myself in IO rank
|
||||
return ioRanks_.found(proci);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use any IO ranks
|
||||
if (ioRanks_.size())
|
||||
{
|
||||
// Find myself in IO rank
|
||||
return findIndex(ioRanks_, proci) != -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Assume all in single communicator
|
||||
return proci == 0;
|
||||
}
|
||||
// Assume all in single communicator
|
||||
return proci == 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ Foam::labelList Foam::fileOperations::hostCollatedFileOperation::subRanks
|
||||
IStringStream is(ioRanksString);
|
||||
labelList ioRanks(is);
|
||||
|
||||
if (findIndex(ioRanks, 0) == -1)
|
||||
if (!ioRanks.found(0))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "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)
|
||||
{
|
||||
if (findIndex(visitedFaces, nbrFacei) == -1)
|
||||
if (!visitedFaces.found(nbrFacei))
|
||||
{
|
||||
testFaces.append(nbrFacei);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user