mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: provide HashTable::iterator::found() method
- This can be used as a convenient alternative to comparing against end().
Eg,
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(methodType);
if (cstrIter.found())
{
...
}
vs.
if (cstrIter != dictionaryConstructorTablePtr_->end())
{
...
}
This commit is contained in:
@ -22,10 +22,9 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
testMapIterators
|
||||
Test-Map
|
||||
|
||||
Description
|
||||
For each time calculate the magnitude of velocity.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -39,9 +38,7 @@ using namespace Foam;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Map<bool> banana;
|
||||
|
||||
banana.insert(5, true);
|
||||
Map<bool> banana{{5, true}};
|
||||
|
||||
// Taking a const iterator from find does not work!
|
||||
// Also, fails later on op==
|
||||
@ -50,7 +47,7 @@ int main(int argc, char *argv[])
|
||||
// This works but now I can change the value.
|
||||
//Map<bool>::iterator bananaIter = banana.find(5);
|
||||
|
||||
if (bananaIter == banana.end())
|
||||
if (!bananaIter.found()) // same as (bananaIter == banana.end())
|
||||
{
|
||||
Info<< "not found" << endl;
|
||||
}
|
||||
@ -62,8 +59,7 @@ int main(int argc, char *argv[])
|
||||
// Same with STL
|
||||
Info<< "Same with STL" << endl;
|
||||
|
||||
std::map<label, bool> STLbanana;
|
||||
STLbanana[5] = true;
|
||||
std::map<label, bool> STLbanana{{5, true}};
|
||||
std::map<label, bool>::const_iterator STLbananaIter = STLbanana.find(5);
|
||||
|
||||
if (STLbananaIter == STLbanana.end())
|
||||
|
||||
@ -403,6 +403,10 @@ public:
|
||||
|
||||
// Access
|
||||
|
||||
//- True if iterator points to a hashedEntry.
|
||||
// This can be used instead of a comparison to end()
|
||||
inline bool found() const;
|
||||
|
||||
//- Return the Key corresponding to the iterator
|
||||
inline const Key& key() const;
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -257,6 +257,14 @@ Foam::HashTable<T, Key, Hash>::iteratorBase::increment()
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
inline bool
|
||||
Foam::HashTable<T, Key, Hash>::iteratorBase::found() const
|
||||
{
|
||||
return entryPtr_;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
inline
|
||||
const Key& Foam::HashTable<T, Key, Hash>::iteratorBase::key() const
|
||||
|
||||
Reference in New Issue
Block a user