HashSet: Added construction from std::initializer_list

This commit is contained in:
Henry Weller
2020-05-09 14:39:31 +01:00
parent 83bd225910
commit 4561d9f813
3 changed files with 25 additions and 11 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -35,23 +35,19 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
wordHashSet setA(0); wordHashSet setA{ "kjhk", "kjhk"};
HashTable<label, word> tableA; HashTable<label, word> tableA;
HashTable<nil> tableB;
Map<label> mapA;
setA.insert("kjhk");
setA.insert("kjhk2");
tableA.insert("value1", 1); tableA.insert("value1", 1);
tableA.insert("value2", 2); tableA.insert("value2", 2);
tableA.insert("value3", 3); tableA.insert("value3", 3);
HashTable<nil> tableB;
tableB.insert("value4", nil()); tableB.insert("value4", nil());
tableB.insert("value5", nil()); tableB.insert("value5", nil());
tableB.insert("value6", nil()); tableB.insert("value6", nil());
Map<label> mapA;
mapA.set(1, 1); mapA.set(1, 1);
mapA.set(2, 2); mapA.set(2, 2);
mapA.set(3, 3); mapA.set(3, 3);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -77,6 +77,21 @@ Foam::HashSet<Key, Hash>::HashSet
} }
template<class Key, class Hash>
Foam::HashSet<Key, Hash>::HashSet
(
std::initializer_list<Key> lst
)
:
HashTable<nil, Key, Hash>(lst.size())
{
for (const Key& key : lst)
{
this->insert(key);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Key, class Hash> template<class Key, class Hash>

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -100,6 +100,9 @@ public:
template<class AnyType, class AnyHash> template<class AnyType, class AnyHash>
HashSet(const HashTable<AnyType, Key, AnyHash>&); HashSet(const HashTable<AnyType, Key, AnyHash>&);
//- Construct from an initializer list
HashSet(std::initializer_list<Key>);
// Member Functions // Member Functions