Commit d36d4a5
Add support for std::hash in wrap-hash directive
This commit adds support for using C++ std::hash<T> specializations
directly in Python bindings via the wrap-hash directive.
Changes:
- Add `cpp_hash` declaration (aliased from std::hash) in generated code
- Support `# wrap-hash:\n# std` syntax to automatically use std::hash<T>
- Maintain backward compatibility with existing expression-based wrap-hash
Usage in .pxd files:
```
cdef cppclass MyClass:
# wrap-hash:
# std
```
This generates:
```python
def __hash__(self):
cdef cpp_hash[MyClass] hasher
return hasher(deref(self.inst.get()))
```
The `cpp_hash` name is used instead of `hash` to avoid conflicts with
Python's built-in hash() function.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent 7b125a1 commit d36d4a5
1 file changed
+29
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
671 | 671 | | |
672 | 672 | | |
673 | 673 | | |
674 | | - | |
675 | | - | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
676 | 691 | | |
677 | 692 | | |
678 | 693 | | |
679 | 694 | | |
680 | 695 | | |
681 | 696 | | |
682 | 697 | | |
683 | | - | |
684 | | - | |
685 | | - | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
686 | 701 | | |
687 | 702 | | |
688 | 703 | | |
| |||
2088 | 2103 | | |
2089 | 2104 | | |
2090 | 2105 | | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
2091 | 2115 | | |
2092 | 2116 | | |
2093 | 2117 | | |
| |||
0 commit comments