diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H index 804ae898cb..5dbde12568 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H @@ -181,7 +181,7 @@ public: // not previously exist in the set. bool insert(const Key& key) { - return this->parent_type::insert(key, zero::null()); + return this->parent_type::emplace(key); } //- Same as insert (no value to overwrite) diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index f7eb66957c..7634a8f50f 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -120,8 +120,8 @@ class HashTable typedef typename std::conditional < std::is_same::type>::value, - Detail::HashTableSingle, - Detail::HashTablePair + Detail::HashTableSingle, + Detail::HashTablePair >::type node_type; @@ -323,7 +323,7 @@ public: ) const; - // Counting + // Counting //- Count the number of keys that satisfy the unary predicate // \param invert changes the logic to select when the predicate @@ -835,7 +835,7 @@ public: }; - //- Iterating over keys only + // Iterator (keys) //- An iterator wrapper for returning a reference to the key template diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableDetail.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableDetail.H index 84d41e678d..ccf53888ff 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableDetail.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableDetail.H @@ -56,17 +56,14 @@ namespace Detail Class isPointer Declaration \*---------------------------------------------------------------------------*/ -//- Test for pointer-like behaviour -template -struct isPointer : public std::is_pointer {}; +//- Pointer-like behaviour +template struct isPointer : std::is_pointer {}; -//- An autoPtr is pointer-like -template -struct isPointer> : public std::true_type {}; +//- Pointer-like behaviour for autoPtr +template struct isPointer> : std::true_type {}; -//- A unique_ptr is pointer-like -template -struct isPointer> : public std::true_type {}; +//- Pointer-like behaviour for std::unique_ptr +template struct isPointer> : std::true_type {}; /*---------------------------------------------------------------------------*\ @@ -77,16 +74,16 @@ struct isPointer> : public std::true_type {}; // Structure with a (K,V) tuple and a linked-list for collisions // Could store key/val as std::pair, but no particular advantage // unless the iterator dereference type changes. -template +template struct HashTablePair { // Types //- Type of key - typedef Key key_type; + typedef K key_type; //- Type of content - typedef T mapped_type; + typedef V mapped_type; //- This struct stores a value static constexpr bool stores_value() @@ -150,7 +147,7 @@ struct HashTablePair } //- Write (key, val) pair - for pointer types - template + template typename std::enable_if::value, void>::type print(Ostream& os) const { @@ -163,7 +160,7 @@ struct HashTablePair } //- Write (key, val) pair - for non-pointer types - template + template typename std::enable_if::value, void>::type print(Ostream& os) const { @@ -178,13 +175,13 @@ struct HashTablePair //- Internal storage type for HashSet entries // Structure with a single (K) value and a linked-list for collisions -template +template struct HashTableSingle { // Types //- Type of key - typedef Key key_type; + typedef K key_type; //- Type of content typedef Foam::zero::null mapped_type; diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H index 9342a71424..d2b70816d2 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H @@ -64,7 +64,7 @@ inline bool Foam::HashTable::empty() const template inline T& Foam::HashTable::at(const Key& key) { - const iterator iter(this->find(key)); + iterator iter(this->find(key)); if (!iter.good()) { @@ -166,10 +166,10 @@ template inline bool Foam::HashTable::insert ( const Key& key, - const T& val + const T& obj ) { - return this->setEntry(false, key, val); + return this->setEntry(false, key, obj); } @@ -177,10 +177,10 @@ template inline bool Foam::HashTable::insert ( const Key& key, - T&& val + T&& obj ) { - return this->setEntry(false, key, std::forward(val)); + return this->setEntry(false, key, std::forward(obj)); } @@ -188,10 +188,10 @@ template inline bool Foam::HashTable::set ( const Key& key, - const T& val + const T& obj ) { - return this->setEntry(true, key, val); // Overwrite + return this->setEntry(true, key, obj); // Overwrite } @@ -199,10 +199,10 @@ template inline bool Foam::HashTable::set ( const Key& key, - T&& val + T&& obj ) { - return this->setEntry(true, key, std::forward(val)); // Overwrite + return this->setEntry(true, key, std::forward(obj)); // Overwrite } @@ -223,48 +223,28 @@ inline const T& Foam::HashTable::lookup template inline T& Foam::HashTable::operator[](const Key& key) { - const iterator iter(this->find(key)); - - if (!iter.good()) - { - FatalErrorInFunction - << key << " not found in table. Valid entries: " - << toc() - << exit(FatalError); - } - - return iter.val(); + return this->at(key); } template inline const T& Foam::HashTable::operator[](const Key& key) const { - const const_iterator iter(this->cfind(key)); - - if (!iter.good()) - { - FatalErrorInFunction - << key << " not found in table. Valid entries: " - << toc() - << exit(FatalError); - } - - return iter.val(); + return this->at(key); } template inline T& Foam::HashTable::operator()(const Key& key) { - const iterator iter(this->find(key)); + iterator iter(this->find(key)); if (iter.good()) { return iter.val(); } - this->insert(key, mapped_type()); + this->emplace(key); return find(key).val(); } @@ -276,7 +256,7 @@ inline T& Foam::HashTable::operator() const T& deflt ) { - const iterator iter(this->find(key)); + iterator iter(this->find(key)); if (iter.good()) {