From 8e63f084b1949428e7b11b0e688603394a76aca9 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Tue, 11 Feb 2020 10:52:28 +0100
Subject: [PATCH] ENH: improve type consistency for HashTable iterators (#1563)

---
 .../containers/HashTables/HashSet/HashSet.C   | 44 +++++----
 .../containers/HashTables/HashSet/HashSet.H   | 61 ++++++------
 .../HashTables/HashTable/HashTable.H          | 97 +++++++++++--------
 .../HashTables/HashTable/HashTableCore.H      | 39 +++-----
 .../HashTables/HashTable/HashTableCoreI.H     | 51 +++-------
 .../HashTables/HashTable/HashTableIterI.H     | 66 +++++--------
 6 files changed, 155 insertions(+), 203 deletions(-)

diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C
index c4012bd368f..227c109a07e 100644
--- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C
+++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2019 OpenCFD Ltd.
+    Copyright (C) 2016-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -246,14 +246,14 @@ inline Foam::label Foam::HashSet<Key, Hash>::unset
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
 template<class Key, class Hash>
-inline bool Foam::HashSet<Key, Hash>::operator()(const Key& key) const
+inline bool Foam::HashSet<Key, Hash>::operator()(const Key& key) const noexcept
 {
     return this->found(key);
 }
 
 
 template<class Key, class Hash>
-inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
+inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const noexcept
 {
     return this->found(key);
 }
@@ -353,6 +353,14 @@ Foam::HashSet<Key, Hash>::operator^=(const HashSet<Key, Hash>& rhs)
 }
 
 
+template<class Key, class Hash>
+inline Foam::HashSet<Key, Hash>&
+Foam::HashSet<Key, Hash>::operator+=(const HashSet<Key, Hash>& rhs)
+{
+    return this->operator|=(rhs);
+}
+
+
 template<class Key, class Hash>
 inline Foam::HashSet<Key, Hash>&
 Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs)
@@ -419,9 +427,9 @@ template<class Key, class Hash>
 inline typename Foam::HashSet<Key, Hash>::iterator
 Foam::HashSet<Key, Hash>::begin()
 {
-    return HashTableCore::iterator_begin<iterator>
+    return iterator
     (
-        static_cast<parent_type&>(*this)
+        static_cast<parent_type&>(*this).begin()
     );
 }
 
@@ -430,9 +438,9 @@ template<class Key, class Hash>
 inline typename Foam::HashSet<Key, Hash>::const_iterator
 Foam::HashSet<Key, Hash>::begin() const
 {
-    return HashTableCore::iterator_cbegin<const_iterator>
+    return const_iterator
     (
-        static_cast<const parent_type&>(*this)
+        static_cast<const parent_type&>(*this).begin()
     );
 }
 
@@ -441,34 +449,34 @@ template<class Key, class Hash>
 inline typename Foam::HashSet<Key, Hash>::const_iterator
 Foam::HashSet<Key, Hash>::cbegin() const
 {
-    return HashTableCore::iterator_cbegin<const_iterator>
+    return const_iterator
     (
-        static_cast<const parent_type&>(*this)
+        static_cast<const parent_type&>(*this).cbegin()
     );
 }
 
 
 template<class Key, class Hash>
-inline const typename Foam::HashSet<Key, Hash>::iterator&
-Foam::HashSet<Key, Hash>::end()
+inline typename Foam::HashSet<Key, Hash>::iterator
+Foam::HashSet<Key, Hash>::end() noexcept
 {
-    return HashTableCore::iterator_end<iterator>();
+    return iterator();
 }
 
 
 template<class Key, class Hash>
-inline const typename Foam::HashSet<Key, Hash>::const_iterator&
-Foam::HashSet<Key, Hash>::end() const
+inline typename Foam::HashSet<Key, Hash>::const_iterator
+Foam::HashSet<Key, Hash>::end() const noexcept
 {
-    return HashTableCore::iterator_cend<const_iterator>();
+    return const_iterator();
 }
 
 
 template<class Key, class Hash>
-inline const typename Foam::HashSet<Key, Hash>::const_iterator&
-Foam::HashSet<Key, Hash>::cend() const
+inline constexpr typename Foam::HashSet<Key, Hash>::const_iterator
+Foam::HashSet<Key, Hash>::cend() const noexcept
 {
-    return HashTableCore::iterator_cend<const_iterator>();
+    return const_iterator();
 }
 
 
diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H
index 0f22599eef4..12af96c818b 100644
--- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H
+++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2019 OpenCFD Ltd.
+    Copyright (C) 2016-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -73,10 +73,9 @@ Description
 namespace Foam
 {
 
-// Forward declarations
+// Forward Declarations
 template<class T> class MinMax;
 
-
 /*---------------------------------------------------------------------------*\
                            Class HashSet Declaration
 \*---------------------------------------------------------------------------*/
@@ -115,12 +114,24 @@ public:
 
     // Constructors
 
-        //- Construct null with default (128) table capacity
+        //- Default construct with default (128) table capacity
         HashSet()
         :
             parent_type()
         {}
 
+        //- Copy construct
+        HashSet(const this_type& rhs)
+        :
+            parent_type(rhs)
+        {}
+
+        //- Move construct
+        HashSet(this_type&& rhs)
+        :
+            parent_type(std::move(rhs))
+        {}
+
         //- Construct given initial table capacity
         explicit HashSet(const label size)
         :
@@ -128,7 +139,7 @@ public:
         {}
 
         //- Construct from Istream with default table capacity
-        HashSet(Istream& is)
+        explicit HashSet(Istream& is)
         :
             parent_type(is)
         {}
@@ -147,18 +158,6 @@ public:
         //- Construct from an initializer list of Key
         HashSet(std::initializer_list<Key> list);
 
-        //- Copy construct
-        HashSet(const this_type& hs)
-        :
-            parent_type(hs)
-        {}
-
-        //- Move construct
-        HashSet(this_type&& hs)
-        :
-            parent_type(std::move(hs))
-        {}
-
         //- Construct from the keys of another HashTable,
         //- the type of values held is arbitrary.
         template<class AnyType, class AnyHash>
@@ -169,7 +168,7 @@ public:
 
         //- Same as found() - return true if key exists in the set.
         //  Method name compatibility with bitSet and boolList.
-        bool test(const Key& key) const
+        bool test(const Key& key) const noexcept
         {
             return found(key);
         }
@@ -291,13 +290,13 @@ public:
 
     // STL iterators
 
-        iterator begin();
-        const_iterator begin() const;
-        const_iterator cbegin() const;
+        inline iterator begin();
+        inline const_iterator begin() const;
+        inline const_iterator cbegin() const;
 
-        const iterator& end();
-        const const_iterator& end() const;
-        const const_iterator& cend() const;
+        inline iterator end() noexcept;
+        inline const_iterator end() const noexcept;
+        inline constexpr const_iterator cend() const noexcept;
 
 
     // Writing
@@ -314,10 +313,10 @@ public:
     // Member Operators
 
         //- Return true if the entry exists, same as found()
-        inline bool operator()(const Key& key) const;
+        inline bool operator()(const Key& key) const noexcept;
 
         //- Return true if the entry exists, same as found().
-        inline bool operator[](const Key& key) const;
+        inline bool operator[](const Key& key) const noexcept;
 
         using parent_type::operator=;
 
@@ -368,13 +367,10 @@ public:
         //- Only retain unique entries (xor)
         this_type& operator^=(const this_type& rhs);
 
-        //- Add entries to this HashSet
-        inline this_type& operator+=(const this_type& rhs)
-        {
-            return this->operator|=(rhs);
-        }
+        //- Add entries to this HashSet. Same as the '|=' operator
+        inline this_type& operator+=(const this_type& rhs);
 
-        //- Remove entries from this HashSet
+        //- Remove entries from this HashSet. Uses erase()
         inline this_type& operator-=(const this_type& rhs);
 
 
@@ -403,7 +399,6 @@ public:
         //- Not applicable for HashSet
         template<class BinaryPredicate>
         label filterEntries(const BinaryPredicate&, const bool) = delete;
-
 };
 
 
diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
index 3f15e87c258..89605dae69a 100644
--- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
+++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2017-2019 OpenCFD Ltd.
+    Copyright (C) 2017-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -105,7 +105,6 @@ template<class T> class UList;
 template<class T, unsigned N> class FixedList;
 template<class T, class Key, class Hash> class HashTable;
 
-
 /*---------------------------------------------------------------------------*\
                           Class HashTable Declaration
 \*---------------------------------------------------------------------------*/
@@ -171,10 +170,17 @@ public:
         //- The third template parameter, the hash index method.
         typedef Hash hasher;
 
+        //- Pointer type for storing into value_type objects.
+        //  This type is usually 'value_type*'.
+        typedef T* pointer;
+
         //- Reference to the stored value_type.
         //  This type is usually 'value_type&'.
         typedef T& reference;
 
+        //- Const pointer type for the stored value_type.
+        typedef const T* const_pointer;
+
         //- Const reference to the stored value_type.
         typedef const T& const_reference;
 
@@ -587,10 +593,10 @@ protected:
 
             //- True if iterator points to an entry
             //  This can be used directly instead of comparing to end()
-            inline bool good() const;
+            inline bool good() const noexcept;
 
             //- True if iterator points to an entry - same as good()
-            inline bool found() const;
+            inline bool found() const noexcept;
 
             //- The key associated with the iterator
             inline const Key& key() const;
@@ -607,11 +613,11 @@ protected:
 
             //- Compare hash-entry element pointers.
             //  Independent of const/non-const access
-            inline bool operator==(const Iterator<true>& iter) const;
-            inline bool operator!=(const Iterator<true>& iter) const;
+            template<bool Any>
+            inline bool operator==(const Iterator<Any>& iter) const noexcept;
 
-            inline bool operator==(const Iterator<false>& iter) const;
-            inline bool operator!=(const Iterator<false>& iter) const;
+            template<bool Any>
+            inline bool operator!=(const Iterator<Any>& iter) const noexcept;
 
 
         protected:
@@ -621,11 +627,11 @@ protected:
 
             //- The selected entry.
             //  MUST be the first member for easy comparison between iterators
-            //  and for reinterpret_cast from nullObject
+            //  and to support reinterpret_cast from nullObject
             node_type* entry_;
 
             //- The hash-table container being iterated on.
-            //  Using a pointer allows default bitwise copy/assignment
+            //  Uses pointer for default copy/assignment
             table_type* container_;
 
             //- Index within the hash-table data.
@@ -636,11 +642,11 @@ protected:
 
         // Protected Constructors
 
-            //- Construct null (end iterator)
-            inline Iterator();
+            //- Default construct (end iterator)
+            inline constexpr Iterator() noexcept;
 
             //- Construct from begin of hash-table
-            inline Iterator(bool, table_type* tbl);
+            inline explicit Iterator(table_type* tbl);
 
             //- Construct by finding key in hash table
             Iterator(table_type* tbl, const Key& key);
@@ -651,10 +657,11 @@ protected:
             //- Increment to the next position
             inline void increment();
 
-            //- Permit an explicit cast to the other (const/non-const) searcher
-            inline explicit operator const Iterator<!Const>&() const
+            //- Permit explicit cast to the other (const/non-const) iterator
+            template<bool Any>
+            explicit operator const Iterator<Any>&() const
             {
-                return *reinterpret_cast<const Iterator<!Const>*>(this);
+                return *reinterpret_cast<const Iterator<Any>*>(this);
             }
         };
 
@@ -680,7 +687,9 @@ public:
             using key_type    = this_type::key_type;
             using mapped_type = this_type::mapped_type;
             using value_type  = this_type::value_type;
+            using pointer     = this_type::pointer;
             using reference   = this_type::reference;
+            using const_pointer = this_type::const_pointer;
             using const_reference = this_type::const_reference;
 
 
@@ -690,7 +699,7 @@ public:
             iterator() = default;
 
             //- Copy construct from similar access type
-            inline explicit iterator(const Iterator<false>& iter)
+            explicit iterator(const Iterator<false>& iter)
             :
                 Iterator<false>(iter)
             {}
@@ -739,10 +748,11 @@ public:
             using key_type    = this_type::key_type;
             using mapped_type = const this_type::mapped_type;
             using value_type  = const this_type::value_type;
+            using pointer     = this_type::const_pointer;
             using reference   = this_type::const_reference;
 
 
-        // Constructors
+        // Generated Methods
 
             //- Default construct (end iterator)
             const_iterator() = default;
@@ -750,23 +760,21 @@ public:
             //- Copy construct
             const_iterator(const const_iterator&) = default;
 
-            //- Copy construct from similar access type
-            inline explicit const_iterator(const Iterator<true>& iter)
-            :
-                Iterator<true>(iter)
-            {}
+            //- Copy assignment
+            const_iterator& operator=(const const_iterator&) = default;
+
 
-            //- Copy construct from dissimilar access type
-            inline explicit const_iterator(const Iterator<false>& iter)
+        // Constructors
+
+            //- Copy construct from any access type
+            template<bool Any>
+            const_iterator(const Iterator<Any>& iter)
             :
-                Iterator<true>
-                (
-                    static_cast<const Iterator<true>&>(iter)
-                )
+                Iterator<true>(static_cast<const Iterator<Any>&>(iter))
             {}
 
             //- Implicit conversion from dissimilar access type
-            inline const_iterator(const iterator& iter)
+            const_iterator(const iterator& iter)
             :
                 const_iterator(reinterpret_cast<const const_iterator&>(iter))
             {}
@@ -790,9 +798,6 @@ public:
 
         // Assignment
 
-            //- Copy assignment
-            const_iterator& operator=(const const_iterator&) = default;
-
             // Allow assign from iterator to const_iterator
             const_iterator& operator=(const iterator& iter)
             {
@@ -815,10 +820,17 @@ public:
         public:
 
             using value_type = this_type::key_type;
+            using pointer    = const Key*;
             using reference  = const Key&;
 
-            //- Implicit conversion
-            inline key_iterator_base(const Iter& iter)
+            //- Default construct (end iterator)
+            constexpr key_iterator_base() noexcept
+            :
+                Iter()
+            {}
+
+            //- Copy construct with implicit conversion
+            explicit key_iterator_base(const Iter& iter)
             :
                 Iter(iter)
             {}
@@ -851,8 +863,7 @@ public:
         //- A const iterator begin/end pair for iterating over keys
         const_iterator_pair<const_key_iterator, this_type> keys() const
         {
-            return
-                const_iterator_pair<const_key_iterator,this_type>(*this);
+            return const_iterator_pair<const_key_iterator, this_type>(*this);
         }
 
 
@@ -867,14 +878,14 @@ public:
         //- const_iterator set to the beginning of the HashTable
         inline const_iterator cbegin() const;
 
-        //- iterator to signal the end for any HashTable
-        inline const iterator& end();
+        //- iterator to signal the end (for any HashTable)
+        inline iterator end() noexcept;
 
-        //- const_iterator to signal the end for any HashTable
-        inline const const_iterator& end() const;
+        //- const_iterator to signal the end (for any HashTable)
+        inline const_iterator end() const noexcept;
 
-        //- const_iterator to signal the end for any HashTable
-        inline const const_iterator& cend() const;
+        //- const_iterator to signal the end (for any HashTable)
+        inline constexpr const_iterator cend() const noexcept;
 
 
     // Writing
diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H
index 6272e9151a6..e483ee17830 100644
--- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H
+++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2017-2019 OpenCFD Ltd.
+    Copyright (C) 2017-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -62,12 +62,12 @@ struct HashTableCore
     //- Return a canonical (power-of-two) of the requested size.
     static label canonicalSize(const label requested_size);
 
-    //- Construct null
-    HashTableCore() = default;
-
-    //- Define template name and debug
+    //- Declare type-name (with debug switch)
     ClassName("HashTable");
 
+    //- Default construct
+    HashTableCore() = default;
+
     static_assert
     (
         sizeof(NullObject) >= sizeof(void*),
@@ -75,34 +75,19 @@ struct HashTableCore
     );
 
 
-    //- Factory method to create a non-const iterator begin
-    template<class IteratorType, class TableType>
-    inline static IteratorType iterator_begin(TableType& table);
-
-    //- Factory method to create a const iterator begin
-    template<class IteratorType, class TableType>
-    inline static IteratorType iterator_cbegin(const TableType& table);
-
-    //- Factory method to return an iterator end
-    //  Simply reinterprets a NullObject as a hash-table iterator.
-    template<class IteratorType>
-    inline static const IteratorType& iterator_end();
-
-    //- Factory method to return an iterator cend
-    //  Simply reinterprets a NullObject as a hash-table iterator.
-    template<class IteratorType>
-    inline static const IteratorType& iterator_cend();
-
-
     //- Factory class for creating a begin/end pair for any const iterator.
     template<class IteratorType, class TableType>
     class const_iterator_pair
     {
-        label size_;
+        const label size_;
         IteratorType iter_;
 
     public:
 
+        //- Default construct an empty pair
+        inline const_iterator_pair();
+
+        //- Construct begin/end pair for table
         inline const_iterator_pair(const TableType& tbl);
 
         label size() const noexcept { return size_; }
@@ -111,8 +96,8 @@ struct HashTableCore
         inline IteratorType begin() const;
         inline IteratorType cbegin() const;
 
-        inline const IteratorType& end() const;
-        inline const IteratorType& cend() const;
+        inline IteratorType end() const;
+        inline IteratorType cend() const;
     };
 };
 
diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableCoreI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableCoreI.H
index e63d60092b8..e4c39787c7c 100644
--- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableCoreI.H
+++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableCoreI.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2017-2019 OpenCFD Ltd.
+    Copyright (C) 2017-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -25,43 +25,16 @@ License
 
 \*---------------------------------------------------------------------------*/
 
-// * * * * * * * * * * * * * * * helper methods  * * * * * * * * * * * * * * //
-
-template<class IteratorType, class TableType>
-inline IteratorType Foam::HashTableCore::iterator_begin
-(
-    TableType& table
-)
-{
-    return IteratorType(table.begin());
-}
-
+// * * * * * * * * * * * * * const iterator pair * * * * * * * * * * * * * * //
 
 template<class IteratorType, class TableType>
-inline IteratorType Foam::HashTableCore::iterator_cbegin
-(
-    const TableType& table
-)
-{
-    return IteratorType(table.cbegin());
-}
-
-
-template<class IteratorType>
-inline const IteratorType& Foam::HashTableCore::iterator_end()
-{
-    return *reinterpret_cast<const IteratorType*>(nullObjectPtr);
-}
-
-
-template<class IteratorType>
-inline const IteratorType& Foam::HashTableCore::iterator_cend()
-{
-    return *reinterpret_cast<const IteratorType*>(nullObjectPtr);
-}
-
+inline Foam::HashTableCore::const_iterator_pair<IteratorType, TableType>
+::const_iterator_pair()
+:
+    size_(0),
+    iter_()
+{}
 
-// * * * * * * * * * * * * * const iterator pair * * * * * * * * * * * * * * //
 
 template<class IteratorType, class TableType>
 inline Foam::HashTableCore::const_iterator_pair<IteratorType, TableType>
@@ -98,24 +71,24 @@ inline IteratorType Foam::HashTableCore::const_iterator_pair
 
 
 template<class IteratorType, class TableType>
-inline const IteratorType& Foam::HashTableCore::const_iterator_pair
+inline IteratorType Foam::HashTableCore::const_iterator_pair
 <
     IteratorType,
     TableType
 >::end() const
 {
-    return HashTableCore::iterator_cend<IteratorType>();
+    return IteratorType();
 }
 
 
 template<class IteratorType, class TableType>
-inline const IteratorType& Foam::HashTableCore::const_iterator_pair
+inline IteratorType Foam::HashTableCore::const_iterator_pair
 <
     IteratorType,
     TableType
 >::cend() const
 {
-    return HashTableCore::iterator_cend<IteratorType>();
+    return IteratorType();
 }
 
 
diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H
index 649828c3dfd..07be2b62a80 100644
--- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H
+++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2017-2019 OpenCFD Ltd.
+    Copyright (C) 2017-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -29,7 +29,8 @@ License
 
 template<class T, class Key, class Hash>
 template<bool Const>
-inline Foam::HashTable<T, Key, Hash>::Iterator<Const>::Iterator()
+inline constexpr
+Foam::HashTable<T, Key, Hash>::Iterator<Const>::Iterator() noexcept
 :
     entry_(nullptr),
     container_(nullptr),
@@ -41,7 +42,6 @@ template<class T, class Key, class Hash>
 template<bool Const>
 inline Foam::HashTable<T, Key, Hash>::Iterator<Const>::Iterator
 (
-    bool, // Future use and to avoid implicit construct
     table_type* tbl
 )
 :
@@ -112,7 +112,7 @@ Foam::HashTable<T, Key, Hash>::Iterator<Const>::increment()
 template<class T, class Key, class Hash>
 template<bool Const>
 inline bool
-Foam::HashTable<T, Key, Hash>::Iterator<Const>::good() const
+Foam::HashTable<T, Key, Hash>::Iterator<Const>::good() const noexcept
 {
     return entry_;
 }
@@ -121,7 +121,7 @@ Foam::HashTable<T, Key, Hash>::Iterator<Const>::good() const
 template<class T, class Key, class Hash>
 template<bool Const>
 inline bool
-Foam::HashTable<T, Key, Hash>::Iterator<Const>::found() const
+Foam::HashTable<T, Key, Hash>::Iterator<Const>::found() const noexcept
 {
     return entry_;
 }
@@ -161,32 +161,11 @@ bool() const noexcept
 
 template<class T, class Key, class Hash>
 template<bool Const>
+template<bool Any>
 inline bool Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator==
 (
-    const Iterator<true>& iter
-) const
-{
-    return entry_ == iter.entry_;
-}
-
-
-template<class T, class Key, class Hash>
-template<bool Const>
-inline bool Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator!=
-(
-    const Iterator<true>& iter
-) const
-{
-    return entry_ != iter.entry_;
-}
-
-
-template<class T, class Key, class Hash>
-template<bool Const>
-inline bool Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator==
-(
-    const Iterator<false>& iter
-) const
+    const Iterator<Any>& iter
+) const noexcept
 {
     return entry_ == iter.entry_;
 }
@@ -194,10 +173,11 @@ inline bool Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator==
 
 template<class T, class Key, class Hash>
 template<bool Const>
+template<bool Any>
 inline bool Foam::HashTable<T, Key, Hash>::Iterator<Const>::operator!=
 (
-    const Iterator<false>& iter
-) const
+    const Iterator<Any>& iter
+) const noexcept
 {
     return entry_ != iter.entry_;
 }
@@ -251,7 +231,7 @@ template<class T, class Key, class Hash>
 inline typename Foam::HashTable<T, Key, Hash>::iterator
 Foam::HashTable<T, Key, Hash>::begin()
 {
-    return iterator(Iterator<false>(true, this));
+    return iterator(Iterator<false>(this));
 }
 
 
@@ -259,7 +239,7 @@ template<class T, class Key, class Hash>
 inline typename Foam::HashTable<T, Key, Hash>::const_iterator
 Foam::HashTable<T, Key, Hash>::begin() const
 {
-    return const_iterator(Iterator<true>(true, this));
+    return const_iterator(Iterator<true>(this));
 }
 
 
@@ -267,31 +247,31 @@ template<class T, class Key, class Hash>
 inline typename Foam::HashTable<T, Key, Hash>::const_iterator
 Foam::HashTable<T, Key, Hash>::cbegin() const
 {
-    return const_iterator(Iterator<true>(true, this));
+    return const_iterator(Iterator<true>(this));
 }
 
 
 template<class T, class Key, class Hash>
-inline const typename Foam::HashTable<T, Key, Hash>::iterator&
-Foam::HashTable<T, Key, Hash>::end()
+inline typename Foam::HashTable<T, Key, Hash>::iterator
+Foam::HashTable<T, Key, Hash>::end() noexcept
 {
-    return iterator_end<iterator>();
+    return iterator();
 }
 
 
 template<class T, class Key, class Hash>
-inline const typename Foam::HashTable<T, Key, Hash>::const_iterator&
-Foam::HashTable<T, Key, Hash>::end() const
+inline typename Foam::HashTable<T, Key, Hash>::const_iterator
+Foam::HashTable<T, Key, Hash>::end() const noexcept
 {
-    return iterator_cend<const_iterator>();
+    return const_iterator();
 }
 
 
 template<class T, class Key, class Hash>
-inline const typename Foam::HashTable<T, Key, Hash>::const_iterator&
-Foam::HashTable<T, Key, Hash>::cend() const
+inline constexpr typename Foam::HashTable<T, Key, Hash>::const_iterator
+Foam::HashTable<T, Key, Hash>::cend() const noexcept
 {
-    return iterator_cend<const_iterator>();
+    return const_iterator();
 }
 
 
-- 
GitLab