Commit 56491280 authored by Robert Bradshaw's avatar Robert Bradshaw

Declare const iterator accessors under another name.

parent 0921b9bc
...@@ -12,8 +12,8 @@ cdef extern from "<deque>" namespace "std" nogil: ...@@ -12,8 +12,8 @@ cdef extern from "<deque>" namespace "std" nogil:
iterator operator--() iterator operator--()
bint operator==(reverse_iterator) bint operator==(reverse_iterator)
bint operator!=(reverse_iterator) bint operator!=(reverse_iterator)
#cppclass const_iterator(iterator): cppclass const_iterator(iterator):
# pass pass
#cppclass const_reverse_iterator(reverse_iterator): #cppclass const_reverse_iterator(reverse_iterator):
# pass # pass
deque() except + deque() except +
...@@ -34,11 +34,11 @@ cdef extern from "<deque>" namespace "std" nogil: ...@@ -34,11 +34,11 @@ cdef extern from "<deque>" namespace "std" nogil:
T& at(size_t) T& at(size_t)
T& back() T& back()
iterator begin() iterator begin()
#const_iterator begin() const_iterator const_begin "begin"()
void clear() void clear()
bint empty() bint empty()
iterator end() iterator end()
#const_iterator end() const_iterator const_end "end"()
iterator erase(iterator) iterator erase(iterator)
iterator erase(iterator, iterator) iterator erase(iterator, iterator)
T& front() T& front()
......
...@@ -24,8 +24,8 @@ cdef extern from "<vector>" namespace "std" nogil: ...@@ -24,8 +24,8 @@ cdef extern from "<vector>" namespace "std" nogil:
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): cppclass const_iterator(iterator):
# pass pass
#cppclass const_reverse_iterator(reverse_iterator): #cppclass const_reverse_iterator(reverse_iterator):
# pass # pass
vector() except + vector() except +
...@@ -46,12 +46,12 @@ cdef extern from "<vector>" namespace "std" nogil: ...@@ -46,12 +46,12 @@ cdef extern from "<vector>" namespace "std" nogil:
T& at(size_t) except + T& at(size_t) except +
T& back() T& back()
iterator begin() iterator begin()
#const_iterator begin() const_iterator const_begin "begin"()
size_t capacity() size_t capacity()
void clear() void clear()
bint empty() bint empty()
iterator end() iterator end()
#const_iterator end() const_iterator const_end "end"()
iterator erase(iterator) iterator erase(iterator)
iterator erase(iterator, iterator) iterator erase(iterator, iterator)
T& front() T& front()
...@@ -70,7 +70,7 @@ cdef extern from "<vector>" namespace "std" nogil: ...@@ -70,7 +70,7 @@ cdef extern from "<vector>" namespace "std" nogil:
void resize(size_t, T&) except + void resize(size_t, T&) except +
size_t size() size_t size()
void swap(vector&) void swap(vector&)
# C++11 methods # C++11 methods
T* data() T* data()
void shrink_to_fit() void shrink_to_fit()
# tag: cpp # tag: cpp
import cython
cimport libcpp cimport libcpp
cimport libcpp.deque cimport libcpp.deque
...@@ -67,3 +69,23 @@ def test_vector_coercion(*args): ...@@ -67,3 +69,23 @@ def test_vector_coercion(*args):
for a in args: for a in args:
v.push_back(a) v.push_back(a)
return [v[0][i] for i in range(v.size())] return [v[0][i] for i in range(v.size())]
def test_const_vector(*args):
"""
>>> test_const_vector(1.75)
[1.75]
>>> test_const_vector(1, 10, 100)
[1.0, 10.0, 100.0]
"""
cdef vector[double] v
for a in args:
v.push_back(a)
return const_vector_to_list(v)
cdef const_vector_to_list(const vector[double]& cv):
cdef vector[double].const_iterator iter = cv.const_begin()
cdef lst = []
while iter != cv.const_end():
lst.append(cython.operator.dereference(iter))
cython.operator.preincrement(iter)
return lst
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