Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
62f776c8
Commit
62f776c8
authored
Oct 24, 2017
by
scoder
Committed by
GitHub
Oct 24, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1870 from Alexhuszagh/master
Bug fix for deque and vector random-access iterators
parents
f22e310d
287202cc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
10 deletions
+81
-10
Cython/Includes/libcpp/deque.pxd
Cython/Includes/libcpp/deque.pxd
+27
-4
Cython/Includes/libcpp/vector.pxd
Cython/Includes/libcpp/vector.pxd
+5
-4
tests/run/cpp_iterators.pyx
tests/run/cpp_iterators.pyx
+49
-2
No files found.
Cython/Includes/libcpp/deque.pxd
View file @
62f776c8
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
+
...
...
Cython/Includes/libcpp/vector.pxd
View file @
62f776c8
...
...
@@ -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
)
...
...
tests/run/cpp_iterators.pyx
View file @
62f776c8
# 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
]
v
int
=
py_v
cdef
vector
[
int
]
result
with
nogil
:
for
item
in
v
:
for
item
in
v
int
:
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()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment