Skip to content

Commit

Permalink
C++: Add "reference_wrapper" declarations to "libcpp.functional" (GH-…
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasr committed Oct 2, 2023
1 parent 1aaabe7 commit 61b5706
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cython/Includes/libcpp/functional.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ cdef extern from "<functional>" namespace "std" nogil:
# https://github.com/cython/cython/issues/3193
greater() except +
bool operator()(const T& lhs, const T& rhs) except +

cdef cppclass reference_wrapper[T]:
reference_wrapper()
reference_wrapper(T)
T& get() const
14 changes: 14 additions & 0 deletions tests/run/cpp_stl_cpp11.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ from libcpp.pair cimport pair
from libcpp.map cimport map
from libcpp.set cimport set
from libcpp.deque cimport deque
from libcpp.functional cimport reference_wrapper


def test_reference_wrapper():
"""
>>> test_reference_wrapper()
'pass'
"""
cdef:
int x = 1
vector[reference_wrapper[int]] ref_wrap_vector
ref_wrap_vector.push_back(reference_wrapper[int](x))
assert ref_wrap_vector[0].get() == 1
return "pass"


def test_vector_functionality():
Expand Down

0 comments on commit 61b5706

Please sign in to comment.