diff --git a/applications/test/HashSet/Test-hashSet.C b/applications/test/HashSet/Test-hashSet.C index eeae7ff0d0..a4593d9daf 100644 --- a/applications/test/HashSet/Test-hashSet.C +++ b/applications/test/HashSet/Test-hashSet.C @@ -40,7 +40,7 @@ using namespace Foam; template void printIf(const Iter& iter) { - if (iter.found()) + if (iter) { Info<< *iter; } diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 7b5e2afb2e..323d5450f0 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -685,8 +685,13 @@ protected: //- The key associated with the iterator inline const Key& key() const; + // Member Operators + //- True if iterator points to an entry + // This can be used directly instead of comparing to end() + explicit inline operator bool() const noexcept; + //- Compare hash-entry element pointers. // Independent of const/non-const access inline bool operator==(const Iterator& iter) const; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H index cc85a8b914..93132e2bc1 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H @@ -124,6 +124,15 @@ inline const Key& Foam::HashTable::Iterator::key() const } +template +template +inline Foam::HashTable::Iterator::operator +bool() const noexcept +{ + return entry_; +} + + template template inline bool Foam::HashTable::Iterator::operator==