mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-23 06:13:07 -06:00
New Core Tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@10538 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
dd88feaf2e
commit
6c22e727de
37 changed files with 3125 additions and 0 deletions
35
tutorial/CoreTutorial/CombineHash.cpp
Normal file
35
tutorial/CoreTutorial/CombineHash.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include "Tutorial.h"
|
||||
|
||||
void CombineHashTutorial()
|
||||
{
|
||||
/// .CombineHash
|
||||
|
||||
/// To simplify providing of high quality hash codes for composite types, U++ provides
|
||||
/// `CombineHash` utility class. This class uses `GetHashValue` function to gather hash
|
||||
/// codes of all values and combines them to provide final hash value for composite type:
|
||||
|
||||
struct Foo {
|
||||
String a;
|
||||
int b;
|
||||
|
||||
unsigned GetHashValue() const { return CombineHash(a, b); }
|
||||
};
|
||||
|
||||
/// Note that `GetHashValue` is defined as function template that calls `GetHashValue`
|
||||
/// method of its argument, therefore defining `GetHashValue` method defines `GetHashValue`
|
||||
/// function too:
|
||||
|
||||
Foo x;
|
||||
x.a = "world";
|
||||
x.b = 22;
|
||||
|
||||
DUMP(GetHashValue(x));
|
||||
|
||||
///
|
||||
|
||||
x.a << '!';
|
||||
|
||||
DUMP(GetHashValue(x));
|
||||
|
||||
///
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue