Access C++ hash functions from Python and vice versa (#1034)

There are two separate additions:

1. `py::hash(obj)` is equivalent to the Python `hash(obj)`.
2. `.def(hash(py::self))` registers the hash function defined by
   `std::hash<T>` as the Python hash function.
This commit is contained in:
Bruce Merry
2017-08-30 14:22:00 +02:00
committed by Dean Moldovan
parent 29b99a11a4
commit 37de2da9dd
7 changed files with 44 additions and 1 deletions

View File

@@ -35,6 +35,8 @@ def test_operator_overloading():
v2 /= v1
assert str(v2) == "[2.000000, 8.000000]"
assert hash(v1) == 4
cstats = ConstructorStats.get(m.Vector2)
assert cstats.alive() == 2
del v1