mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
35 lines
799 B
C++
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));
|
|
|
|
///
|
|
}
|