ultimatepp/tutorial/CoreTutorial/CombineHash.cpp
cxl 2fa5bd86a1 New Core Tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@10538 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2016-12-12 10:08:40 +00:00

35 lines
799 B
C++

#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));
///
}