Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default templates to std::unordered_map #3155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cython/Includes/libcpp/unordered_map.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .utility cimport pair

cdef extern from "<unordered_map>" namespace "std" nogil:
cdef cppclass unordered_map[T, U]:
cdef cppclass unordered_map[T, U, HASH=*, PRED=*, ALLOCATOR=*]:
ctypedef T key_type
ctypedef U mapped_type
ctypedef pair[const T, U] value_type
Expand Down
6 changes: 6 additions & 0 deletions tests/run/libcpp_all.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cimport libcpp.stack
cimport libcpp.vector
cimport libcpp.complex
cimport libcpp.limits
cimport libcpp.unordered_map

from libcpp.deque cimport *
from libcpp.list cimport *
Expand All @@ -25,6 +26,8 @@ from libcpp.stack cimport *
from libcpp.vector cimport *
from libcpp.complex cimport *
from libcpp.limits cimport *
from libcpp.unordered_map cimport *
from libcpp_all_helper cimport *

cdef libcpp.deque.deque[int] d1 = deque[int]()
cdef libcpp.list.list[int] l1 = list[int]()
Expand Down Expand Up @@ -118,6 +121,9 @@ assert vec_alloc_int.size() == 10
cdef libcpp.list.list[int,allocator[int]] list_alloc_int = libcpp.list.list[int,allocator[int]](10,1)
assert list_alloc_int.size() == 10

cdef libcpp.unordered_map.unordered_map[MyStruct, int, Hasher].iterator start = map_with_specific_hasher.begin()
assert start == map_with_specific_hasher.end()

##Something about the default params breaks the auto-conversion...
def convert_to_vector(I):
"""
Expand Down
15 changes: 15 additions & 0 deletions tests/run/libcpp_all_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <unordered_map>

struct MyStruct {
bool operator == (const MyStruct & rhs) const {
return true;
}
};

struct Hasher {
std::size_t operator()(const MyStruct & val) const {
return 0;
}
};

std::unordered_map<MyStruct, int, Hasher> map_with_specific_hasher;
10 changes: 10 additions & 0 deletions tests/run/libcpp_all_helper.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from libcpp.unordered_map cimport unordered_map

cdef extern from "libcpp_all_helper.h":
cdef cppclass MyStruct:
pass

cdef cppclass Hasher:
pass

cdef unordered_map[MyStruct, int] map_with_specific_hasher