Commit eb3e5e6e authored by Robert Bradshaw's avatar Robert Bradshaw

Don't forget std::list.

parent 4a57c2c3
......@@ -2987,7 +2987,7 @@ class CStructOrUnionType(CType):
return super(CStructOrUnionType, self).cast_code(expr_code)
builtin_cpp_conversions = ("std::string", "std::vector", "std::set", "std::map", "std::pair")
builtin_cpp_conversions = ("std::string", "std::vector", "std::list", "std::set", "std::map", "std::pair")
class CppClassType(CType):
# name string
......
......@@ -74,8 +74,8 @@ cdef extern from *:
void push_back(T&)
@cname("{{cname}}")
cdef cpp_list[{{T0}}] {{cname}}(object o) except *:
cdef cpp_list[{{T0}}] l
cdef cpp_list[X] {{cname}}(object o) except *:
cdef cpp_list[X] l
for item in o:
l.push_back(X_from_py(item))
return l
......@@ -83,6 +83,8 @@ cdef cpp_list[{{T0}}] {{cname}}(object o) except *:
#################### list.to_py ####################
cimport cython
cdef extern from *:
ctypedef struct X "{{T0}}":
pass
......@@ -96,13 +98,14 @@ cdef extern from *:
bint operator!=(const_iterator)
const_iterator begin()
const_iterator end()
cdef cppclass const_cpp_list "const std::list" [T] (cpp_list)
cdef cppclass const_cpp_list "const std::list" [T] (cpp_list):
pass
@cname("{{cname}}")
cdef object {{cname}}(const_cpp_list[X]& v):
o = []
cdef cpp_list[X].const_iterator iter = s.begin()
while iter != s.end():
cdef cpp_list[X].const_iterator iter = v.begin()
while iter != v.end():
o.append(X_to_py(cython.operator.dereference(iter)))
cython.operator.preincrement(iter)
return o
......
......@@ -6,6 +6,7 @@ from libcpp.set cimport set as cpp_set
from libcpp.string cimport string
from libcpp.pair cimport pair
from libcpp.vector cimport vector
from libcpp.list cimport list as cpp_list
py_set = set
......@@ -67,6 +68,14 @@ def test_pair(o):
cdef pair[long, double] p = o
return p
def test_list(o):
"""
>>> test_list([1, 2, 3])
[1, 2, 3]
"""
cdef cpp_list[int] l = o
return l
def test_set(o):
"""
>>> sorted(test_set([1, 2, 3]))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment