Commit 009865af authored by Robert Bradshaw's avatar Robert Bradshaw Committed by GitHub

Merge pull request #1597 from quantopian/vector-cleanups

Vector cleanups
parents 68336b38 935b691c
...@@ -2,13 +2,20 @@ cdef extern from "<vector>" namespace "std" nogil: ...@@ -2,13 +2,20 @@ cdef extern from "<vector>" namespace "std" nogil:
cdef cppclass vector[T,ALLOCATOR=*]: cdef cppclass vector[T,ALLOCATOR=*]:
ctypedef T value_type ctypedef T value_type
ctypedef ALLOCATOR allocator_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: cppclass iterator:
T& operator*() T& operator*()
iterator operator++() iterator operator++()
iterator operator--() iterator operator--()
iterator operator+(size_t) iterator operator+(size_type)
iterator operator-(size_t) iterator operator-(size_type)
size_t operator-(iterator) difference_type operator-(iterator)
bint operator==(iterator) bint operator==(iterator)
bint operator!=(iterator) bint operator!=(iterator)
bint operator<(iterator) bint operator<(iterator)
...@@ -19,8 +26,8 @@ cdef extern from "<vector>" namespace "std" nogil: ...@@ -19,8 +26,8 @@ cdef extern from "<vector>" namespace "std" nogil:
T& operator*() T& operator*()
iterator operator++() iterator operator++()
iterator operator--() iterator operator--()
iterator operator+(size_t) iterator operator+(size_type)
iterator operator-(size_t) iterator operator-(size_type)
bint operator==(reverse_iterator) bint operator==(reverse_iterator)
bint operator!=(reverse_iterator) bint operator!=(reverse_iterator)
bint operator<(reverse_iterator) bint operator<(reverse_iterator)
...@@ -33,10 +40,10 @@ cdef extern from "<vector>" namespace "std" nogil: ...@@ -33,10 +40,10 @@ cdef extern from "<vector>" namespace "std" nogil:
pass pass
vector() except + vector() except +
vector(vector&) except + vector(vector&) except +
vector(size_t) except + vector(size_type) except +
vector(size_t, T&) except + vector(size_type, T&) except +
#vector[input_iterator](input_iterator, input_iterator) #vector[input_iterator](input_iterator, input_iterator)
T& operator[](size_t) T& operator[](size_type)
#vector& operator=(vector&) #vector& operator=(vector&)
bint operator==(vector&, vector&) bint operator==(vector&, vector&)
bint operator!=(vector&, vector&) bint operator!=(vector&, vector&)
...@@ -44,13 +51,13 @@ cdef extern from "<vector>" namespace "std" nogil: ...@@ -44,13 +51,13 @@ cdef extern from "<vector>" namespace "std" nogil:
bint operator>(vector&, vector&) bint operator>(vector&, vector&)
bint operator<=(vector&, vector&) bint operator<=(vector&, vector&)
bint operator>=(vector&, vector&) bint operator>=(vector&, vector&)
void assign(size_t, const T&) void assign(size_type, const T&)
void assign[input_iterator](input_iterator, input_iterator) except + void assign[input_iterator](input_iterator, input_iterator) except +
T& at(size_t) except + T& at(size_type) except +
T& back() T& back()
iterator begin() iterator begin()
const_iterator const_begin "begin"() const_iterator const_begin "begin"()
size_t capacity() size_type capacity()
void clear() void clear()
bint empty() bint empty()
iterator end() iterator end()
...@@ -59,19 +66,19 @@ cdef extern from "<vector>" namespace "std" nogil: ...@@ -59,19 +66,19 @@ cdef extern from "<vector>" namespace "std" nogil:
iterator erase(iterator, iterator) iterator erase(iterator, iterator)
T& front() T& front()
iterator insert(iterator, const T&) except + iterator insert(iterator, const T&) except +
void insert(iterator, size_t, const T&) except + iterator insert(iterator, size_type, const T&) except +
void insert[Iter](iterator, Iter, Iter) except + iterator insert[Iter](iterator, Iter, Iter) except +
size_t max_size() size_type max_size()
void pop_back() void pop_back()
void push_back(T&) except + void push_back(T&) except +
reverse_iterator rbegin() reverse_iterator rbegin()
const_reverse_iterator const_rbegin "rbegin"() const_reverse_iterator const_rbegin "crbegin"()
reverse_iterator rend() reverse_iterator rend()
const_reverse_iterator const_rend "rend"() const_reverse_iterator const_rend "crend"()
void reserve(size_t) void reserve(size_type)
void resize(size_t) except + void resize(size_type) except +
void resize(size_t, T&) except + void resize(size_type, T&) except +
size_t size() size_type size()
void swap(vector&) void swap(vector&)
# C++11 methods # C++11 methods
......
...@@ -195,3 +195,18 @@ def test_typedef_vector(L): ...@@ -195,3 +195,18 @@ def test_typedef_vector(L):
vb.insert(vb.begin(), vb2.begin(), vb2.end()) vb.insert(vb.begin(), vb2.begin(), vb2.end())
return vi, vi.at(0), vb, vb.at(0) return vi, vi.at(0), vb, vb.at(0)
def test_insert():
"""
>>> test_insert()
"""
cdef vector[int] v
cdef vector[int].size_type count = 5
cdef int value = 0
v.insert(v.end(), count, value)
assert v.size() == count
for element in v:
assert element == value, '%s != %s' % (element, count)
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