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:
iterator operator--()
bint operator==(reverse_iterator)
bint operator!=(reverse_iterator)
#cppclass const_iterator(iterator):
# pass
cppclass const_iterator(iterator):
pass
#cppclass const_reverse_iterator(reverse_iterator):
# pass
deque() except +
......@@ -34,11 +34,11 @@ cdef extern from "<deque>" namespace "std" nogil:
T& at(size_t)
T& back()
iterator begin()
#const_iterator begin()
const_iterator const_begin "begin"()
void clear()
bint empty()
iterator end()
#const_iterator end()
const_iterator const_end "end"()
iterator erase(iterator)
iterator erase(iterator, iterator)
T& front()
......
......@@ -24,8 +24,8 @@ cdef extern from "<vector>" namespace "std" nogil:
bint operator>(reverse_iterator)
bint operator<=(reverse_iterator)
bint operator>=(reverse_iterator)
#cppclass const_iterator(iterator):
# pass
cppclass const_iterator(iterator):
pass
#cppclass const_reverse_iterator(reverse_iterator):
# pass
vector() except +
......@@ -46,12 +46,12 @@ cdef extern from "<vector>" namespace "std" nogil:
T& at(size_t) except +
T& back()
iterator begin()
#const_iterator begin()
const_iterator const_begin "begin"()
size_t capacity()
void clear()
bint empty()
iterator end()
#const_iterator end()
const_iterator const_end "end"()
iterator erase(iterator)
iterator erase(iterator, iterator)
T& front()
......@@ -70,7 +70,7 @@ cdef extern from "<vector>" namespace "std" nogil:
void resize(size_t, T&) except +
size_t size()
void swap(vector&)
# C++11 methods
T* data()
void shrink_to_fit()
# tag: cpp
import cython
cimport libcpp
cimport libcpp.deque
......@@ -67,3 +69,23 @@ def test_vector_coercion(*args):
for a in args:
v.push_back(a)
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