Commit 275a59af authored by Henry Weller's avatar Henry Weller
Browse files

HashTable: Added void operator=(std::initializer_list<Tuple2<Key, T>>)

parent e3802230
...@@ -165,6 +165,16 @@ int main() ...@@ -165,6 +165,16 @@ int main()
table3.clearStorage(); table3.clearStorage();
Info<< table3 << nl; Info<< table3 << nl;
table1 =
{
{"aca", 3.0},
{"aaw", 6.0},
{"acr", 8.0},
{"aec", 10.0}
};
Info<< "\ntable1" << table1 << nl;
Info<< "\nDone\n"; Info<< "\nDone\n";
return 0; return 0;
......
...@@ -563,6 +563,29 @@ void Foam::HashTable<T, Key, Hash>::operator= ...@@ -563,6 +563,29 @@ void Foam::HashTable<T, Key, Hash>::operator=
} }
template<class T, class Key, class Hash>
void Foam::HashTable<T, Key, Hash>::operator=
(
std::initializer_list<Tuple2<Key, T>> lst
)
{
// Could be zero-sized from a previous transfer()
if (!tableSize_)
{
resize(lst.size());
}
else
{
clear();
}
for (const Tuple2<Key, T>& pair : lst)
{
insert(pair.first(), pair.second());
}
}
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::operator== bool Foam::HashTable<T, Key, Hash>::operator==
( (
......
...@@ -213,7 +213,7 @@ public: ...@@ -213,7 +213,7 @@ public:
HashTable(const Xfer<HashTable<T, Key, Hash>>&); HashTable(const Xfer<HashTable<T, Key, Hash>>&);
//- Construct from an initializer list //- Construct from an initializer list
HashTable(std::initializer_list<Tuple2<Key, T>> lst); HashTable(std::initializer_list<Tuple2<Key, T>>);
//- Destructor //- Destructor
...@@ -315,6 +315,9 @@ public: ...@@ -315,6 +315,9 @@ public:
//- Assignment //- Assignment
void operator=(const HashTable<T, Key, Hash>&); void operator=(const HashTable<T, Key, Hash>&);
//- Assignment to an initializer list
void operator=(std::initializer_list<Tuple2<Key, T>>);
//- Equality. Hash tables are equal if the keys and values are equal. //- Equality. Hash tables are equal if the keys and values are equal.
// Independent of table storage size and table order. // Independent of table storage size and table order.
bool operator==(const HashTable<T, Key, Hash>&) const; bool operator==(const HashTable<T, Key, Hash>&) const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment