diff options
Diffstat (limited to 'tests/run/cpp_stl_list_cpp11.pyx')
-rw-r--r-- | tests/run/cpp_stl_list_cpp11.pyx | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/run/cpp_stl_list_cpp11.pyx b/tests/run/cpp_stl_list_cpp11.pyx new file mode 100644 index 000000000..b8a480283 --- /dev/null +++ b/tests/run/cpp_stl_list_cpp11.pyx @@ -0,0 +1,45 @@ +# mode: run +# tag: cpp, werror, no-cpp-locals, cpp11 + +from cython.operator cimport dereference as deref +from cython.operator cimport preincrement as incr + +from libcpp.list cimport list as cpp_list + +def const_iteration_test(L): + """ + >>> const_iteration_test([1,2,4,8]) + 1 + 2 + 4 + 8 + """ + l = new cpp_list[int]() + try: + for a in L: + l.push_back(a) + it = l.cbegin() + while it != l.cend(): + a = deref(it) + incr(it) + print(a) + finally: + del l + +cdef list const_to_pylist(cpp_list[int]& l): + cdef list L = [] + it = l.cbegin() + while it != l.cend(): + L.append(deref(it)) + incr(it) + return L + +def const_item_ptr_test(L, int x): + """ + >>> const_item_ptr_test(range(10), 100) + [100, 1, 2, 3, 4, 5, 6, 7, 8, 9] + """ + cdef cpp_list[int] l = L + cdef int* li_ptr = &l.front() + li_ptr[0] = x + return const_to_pylist(l) |