Commit 62f776c8 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #1870 from Alexhuszagh/master

Bug fix for deque and vector random-access iterators
parents f22e310d 287202cc
cdef extern from "<deque>" namespace "std" nogil:
cdef cppclass deque[T,ALLOCATOR=*]:
ctypedef T value_type
ctypedef ALLOCATOR allocator_type
# these should really be allocator_type.size_type and
# allocator_type.difference_type to be true to the C++ definition
# but cython doesn't support defered access on template arguments
ctypedef size_t size_type
ctypedef ptrdiff_t difference_type
cppclass iterator:
T& operator*()
iterator operator++()
iterator operator--()
iterator operator+(size_type)
iterator operator-(size_type)
difference_type operator-(iterator)
bint operator==(iterator)
bint operator!=(iterator)
bint operator<(iterator)
bint operator>(iterator)
bint operator<=(iterator)
bint operator>=(iterator)
cppclass reverse_iterator:
T& operator*()
iterator operator++()
iterator operator--()
reverse_iterator operator++()
reverse_iterator operator--()
reverse_iterator operator+(size_type)
reverse_iterator operator-(size_type)
difference_type operator-(reverse_iterator)
bint operator==(reverse_iterator)
bint operator!=(reverse_iterator)
bint operator<(reverse_iterator)
bint operator>(reverse_iterator)
bint operator<=(reverse_iterator)
bint operator>=(reverse_iterator)
cppclass const_iterator(iterator):
pass
#cppclass const_reverse_iterator(reverse_iterator):
# pass
cppclass const_reverse_iterator(reverse_iterator):
pass
deque() except +
deque(deque&) except +
deque(size_t) except +
......
......@@ -24,10 +24,11 @@ cdef extern from "<vector>" namespace "std" nogil:
bint operator>=(iterator)
cppclass reverse_iterator:
T& operator*()
iterator operator++()
iterator operator--()
iterator operator+(size_type)
iterator operator-(size_type)
reverse_iterator operator++()
reverse_iterator operator--()
reverse_iterator operator+(size_type)
reverse_iterator operator-(size_type)
difference_type operator-(reverse_iterator)
bint operator==(reverse_iterator)
bint operator!=(reverse_iterator)
bint operator<(reverse_iterator)
......
# mode: run
# tag: cpp, werror
from libcpp.deque cimport deque
from libcpp.vector cimport vector
from cython.operator cimport dereference as deref
......@@ -15,13 +16,59 @@ def test_vector(py_v):
>>> test_vector([1, 2, 3])
[1, 2, 3]
"""
cdef vector[int] v = py_v
cdef vector[int] vint = py_v
cdef vector[int] result
with nogil:
for item in v:
for item in vint:
result.push_back(item)
return result
def test_deque_iterator_subtraction(py_v):
"""
>>> test_deque_iterator_subtraction([1, 2, 3])
3
"""
cdef deque[int] dint
for i in py_v:
dint.push_back(i)
cdef deque[int].iterator first = dint.begin()
cdef deque[int].iterator last = dint.end()
return last - first
def test_vector_iterator_subtraction(py_v):
"""
>>> test_vector_iterator_subtraction([1, 2, 3])
3
"""
cdef vector[int] vint = py_v
cdef vector[int].iterator first = vint.begin()
cdef vector[int].iterator last = vint.end()
return last - first
def test_deque_iterator_addition(py_v):
"""
>>> test_deque_iterator_addition([2, 4, 6])
6
"""
cdef deque[int] dint
for i in py_v:
dint.push_back(i)
cdef deque[int].iterator first = dint.begin()
return deref(first+2)
def test_vector_iterator_addition(py_v):
"""
>>> test_vector_iterator_addition([2, 4, 6])
6
"""
cdef vector[int] vint = py_v
cdef vector[int].iterator first = vint.begin()
return deref(first+2)
def test_ptrs():
"""
>>> test_ptrs()
......
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