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()
table3.clearStorage();
Info<< table3 << nl;
table1 =
{
{"aca", 3.0},
{"aaw", 6.0},
{"acr", 8.0},
{"aec", 10.0}
};
Info<< "\ntable1" << table1 << nl;
Info<< "\nDone\n";
return 0;
......
......@@ -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>
bool Foam::HashTable<T, Key, Hash>::operator==
(
......
......@@ -213,7 +213,7 @@ public:
HashTable(const Xfer<HashTable<T, Key, Hash>>&);
//- Construct from an initializer list
HashTable(std::initializer_list<Tuple2<Key, T>> lst);
HashTable(std::initializer_list<Tuple2<Key, T>>);
//- Destructor
......@@ -315,6 +315,9 @@ public:
//- Assignment
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.
// Independent of table storage size and table order.
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