mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 06:05:58 -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
31
tutorial/CoreTutorial/IndexClient.cpp
Normal file
31
tutorial/CoreTutorial/IndexClient.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include "Tutorial.h"
|
||||
|
||||
void IndexClient()
|
||||
{
|
||||
/// .Index and client types
|
||||
|
||||
/// In order to store elements to `Index`, they type must be `Moveable`, have deep copy and
|
||||
/// defined the `operator==` and a `GetHashValue` function or method to compute the hash
|
||||
/// code. It is recommended to use `CombineHash` to combine hash values of types that
|
||||
/// already provide `GetHashValue`:
|
||||
|
||||
struct Person : Moveable<Person> {
|
||||
String name;
|
||||
String surname;
|
||||
|
||||
unsigned GetHashValue() const { return CombineHash(name, surname); }
|
||||
bool operator==(const Person& b) const { return name == b.name && surname == b.surname; }
|
||||
|
||||
Person(String name, String surname) : name(name), surname(surname) {}
|
||||
Person() {}
|
||||
};
|
||||
|
||||
Index<Person> p;
|
||||
p.Add(Person("John", "Smith"));
|
||||
p.Add(Person("Paul", "Carpenter"));
|
||||
p.Add(Person("Carl", "Engles"));
|
||||
|
||||
DUMP(p.Find(Person("Paul", "Carpenter")));
|
||||
|
||||
///
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue