mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: HashTable documentation
- explicitly mention the value-initialized status for the operator().
This means that the following code will properly use an initialized
zero.
HashTable<label> regionCount;
if (...)
regionCount("region1")++;
... and also this;
if (regionCount("something") > 0)
{
...
}
Note that the OpenFOAM HashTable uses operator[] to provide read and
write access to *existing* entries and will provoke a FatalError if
the entry does not exist.
The operator() provides write access to *existing* entries or will
create the new entry as required.
The STL hashes use operator[] for this purpose.
This commit is contained in:
@ -28,6 +28,7 @@ Description
|
||||
#include "hashedWordList.H"
|
||||
#include "HashSet.H"
|
||||
#include "Map.H"
|
||||
#include "labelPairHashes.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -122,7 +123,6 @@ int main(int argc, char *argv[])
|
||||
<< (wordHashSet(setA) | wordHashSet(tableA) | wordHashSet(tableB))
|
||||
<< nl;
|
||||
|
||||
|
||||
labelHashSet setB
|
||||
{
|
||||
1, 11, 42
|
||||
@ -130,6 +130,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< "setB : " << setB << endl;
|
||||
|
||||
labelPair pair(12, 15);
|
||||
setB.set(pair);
|
||||
|
||||
Info<< "setB : " << setB << endl;
|
||||
setB.unset(pair);
|
||||
|
||||
|
||||
labelHashSet setC(1);
|
||||
setC.insert(2008);
|
||||
setC.insert(1984);
|
||||
|
||||
@ -51,6 +51,9 @@ void printTraits(const pTraits<T>& p)
|
||||
}
|
||||
|
||||
|
||||
#pragma GCC diagnostic warning "-Wmaybe-uninitialized"
|
||||
#pragma GCC diagnostic warning "-Wuninitialized"
|
||||
|
||||
int main()
|
||||
{
|
||||
printTraits<bool>();
|
||||
@ -71,6 +74,12 @@ int main()
|
||||
|
||||
printTraits(pTraits<scalar>(3.14159));
|
||||
|
||||
label abc;
|
||||
Info<< "unintialized primitive:"<< abc << endl;
|
||||
|
||||
label def = label();
|
||||
Info<< "intialized primitive:"<< def << endl;
|
||||
|
||||
Info<< "End\n" << endl;
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user