Commit 57582f62 authored by Max Bachmann's avatar Max Bachmann Committed by GitHub

Add cbegin/cend/crbegin/crend to C++ STL container declarations (GH-4530)

parent f212c3e4
......@@ -58,10 +58,12 @@ cdef extern from "<deque>" namespace "std" nogil:
T& back()
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
void clear()
bint empty()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
iterator erase(iterator) except +
iterator erase(iterator, iterator) except +
T& front()
......@@ -75,8 +77,10 @@ cdef extern from "<deque>" namespace "std" nogil:
void push_front(T&) except +
reverse_iterator rbegin()
#const_reverse_iterator rbegin()
const_reverse_iterator crbegin()
reverse_iterator rend()
#const_reverse_iterator rend()
const_reverse_iterator crend()
void resize(size_t) except +
void resize(size_t, T&) except +
size_t size()
......
......@@ -43,10 +43,12 @@ cdef extern from "<list>" namespace "std" nogil:
T& back()
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
void clear()
bint empty()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
iterator erase(iterator)
iterator erase(iterator, iterator)
T& front()
......@@ -61,10 +63,12 @@ cdef extern from "<list>" namespace "std" nogil:
void push_front(T&) except +
reverse_iterator rbegin()
const_reverse_iterator const_rbegin "rbegin"()
const_reverse_iterator crbegin()
void remove(T&) except +
#void remove_if(UnPred)
reverse_iterator rend()
const_reverse_iterator const_rend "rend"()
const_reverse_iterator crend()
void resize(size_t, T&) except +
void reverse()
size_t size()
......
......@@ -48,11 +48,13 @@ cdef extern from "<map>" namespace "std" nogil:
const U& const_at "at"(const T&) except +
iterator begin()
const_iterator const_begin "begin" ()
const_iterator cbegin()
void clear()
size_t count(const T&)
bint empty()
iterator end()
const_iterator const_end "end" ()
const_iterator cend()
pair[iterator, iterator] equal_range(const T&)
pair[const_iterator, const_iterator] const_equal_range "equal_range"(const T&)
iterator erase(iterator)
......@@ -70,8 +72,10 @@ cdef extern from "<map>" namespace "std" nogil:
size_t max_size()
reverse_iterator rbegin()
const_reverse_iterator const_rbegin "rbegin"()
const_reverse_iterator crbegin()
reverse_iterator rend()
const_reverse_iterator const_rend "rend"()
const_reverse_iterator crend()
size_t size()
void swap(map&)
iterator upper_bound(const T&)
......@@ -122,11 +126,13 @@ cdef extern from "<map>" namespace "std" nogil:
bint operator>=(const multimap&, const multimap&)
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
void clear()
size_t count(const T&)
bint empty()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
pair[iterator, iterator] equal_range(const T&)
pair[const_iterator, const_iterator] const_equal_range "equal_range"(const T&)
iterator erase(iterator)
......@@ -144,8 +150,10 @@ cdef extern from "<map>" namespace "std" nogil:
size_t max_size()
reverse_iterator rbegin()
const_reverse_iterator const_rbegin "rbegin"()
const_reverse_iterator crbegin()
reverse_iterator rend()
const_reverse_iterator const_rend "rend"()
const_reverse_iterator crend()
size_t size()
void swap(multimap&)
iterator upper_bound(const T&)
......
......@@ -41,11 +41,13 @@ cdef extern from "<set>" namespace "std" nogil:
bint operator>=(set&, set&)
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
void clear()
size_t count(const T&)
bint empty()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
pair[iterator, iterator] equal_range(const T&)
pair[const_iterator, const_iterator] const_equal_range "equal_range"(const T&)
iterator erase(iterator)
......@@ -64,8 +66,10 @@ cdef extern from "<set>" namespace "std" nogil:
size_t max_size()
reverse_iterator rbegin()
const_reverse_iterator const_rbegin "rbegin"()
const_reverse_iterator crbegin()
reverse_iterator rend()
const_reverse_iterator const_rend "rend"()
const_reverse_iterator crend()
size_t size()
void swap(set&)
iterator upper_bound(const T&)
......@@ -114,11 +118,13 @@ cdef extern from "<set>" namespace "std" nogil:
bint operator>=(multiset&, multiset&)
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
void clear()
size_t count(const T&)
bint empty()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
pair[iterator, iterator] equal_range(const T&)
pair[const_iterator, const_iterator] const_equal_range "equal_range"(const T&)
iterator erase(iterator)
......@@ -137,8 +143,10 @@ cdef extern from "<set>" namespace "std" nogil:
size_t max_size()
reverse_iterator rbegin()
const_reverse_iterator const_rbegin "rbegin"()
const_reverse_iterator crbegin()
reverse_iterator rend()
const_reverse_iterator const_rend "rend"()
const_reverse_iterator crend()
size_t size()
void swap(multiset&)
iterator upper_bound(const T&)
......
......@@ -47,12 +47,16 @@ cdef extern from "<string>" namespace "std" nogil:
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
reverse_iterator rbegin()
const_reverse_iterator const_rbegin "rbegin"()
const_reverse_iterator crbegin()
reverse_iterator rend()
const_reverse_iterator const_rend "rend"()
const_reverse_iterator crend()
const char* c_str()
const char* data()
......
......@@ -32,11 +32,13 @@ cdef extern from "<unordered_map>" namespace "std" nogil:
const U& const_at "at"(const T&) except +
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
void clear()
size_t count(const T&)
bint empty()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
pair[iterator, iterator] equal_range(const T&)
pair[const_iterator, const_iterator] const_equal_range "equal_range"(const T&)
iterator erase(iterator)
......@@ -95,6 +97,7 @@ cdef extern from "<unordered_map>" namespace "std" nogil:
bint operator>=(const unordered_multimap&, const unordered_multimap&)
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
#local_iterator begin(size_t)
#const_local_iterator const_begin "begin"(size_t)
void clear()
......@@ -102,6 +105,7 @@ cdef extern from "<unordered_map>" namespace "std" nogil:
bint empty()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
#local_iterator end(size_t)
#const_local_iterator const_end "end"(size_t)
pair[iterator, iterator] equal_range(const T&)
......
......@@ -21,11 +21,13 @@ cdef extern from "<unordered_set>" namespace "std" nogil:
bint operator!=(unordered_set&, unordered_set&)
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
void clear()
size_t count(const T&)
bint empty()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
pair[iterator, iterator] equal_range(const T&)
pair[const_iterator, const_iterator] const_equal_range "equal_range"(const T&)
iterator erase(iterator)
......@@ -73,11 +75,13 @@ cdef extern from "<unordered_set>" namespace "std" nogil:
bint operator!=(unordered_multiset&, unordered_multiset&)
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
void clear()
size_t count(const T&)
bint empty()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
pair[iterator, iterator] equal_range(const T&)
pair[const_iterator, const_iterator] const_equal_range "equal_range"(const T&)
iterator erase(iterator)
......
......@@ -58,11 +58,13 @@ cdef extern from "<vector>" namespace "std" nogil:
T& back()
iterator begin()
const_iterator const_begin "begin"()
const_iterator cbegin()
size_type capacity()
void clear()
bint empty()
iterator end()
const_iterator const_end "end"()
const_iterator cend()
iterator erase(iterator)
iterator erase(iterator, iterator)
T& front()
......@@ -73,9 +75,11 @@ cdef extern from "<vector>" namespace "std" nogil:
void pop_back()
void push_back(T&) except +
reverse_iterator rbegin()
const_reverse_iterator const_rbegin "crbegin"()
const_reverse_iterator const_rbegin "rbegin"()
const_reverse_iterator crbegin()
reverse_iterator rend()
const_reverse_iterator const_rend "crend"()
const_reverse_iterator const_rend "rend"()
const_reverse_iterator crend()
void reserve(size_type) except +
void resize(size_type) except +
void resize(size_type, T&) except +
......
......@@ -61,6 +61,26 @@ def iteration_test(L):
finally:
del l
def const_iteration_test(L):
"""
>>> const_iteration_test([1,2,4,8])
1
2
4
8
"""
l = new cpp_list[int]()
try:
for a in L:
l.push_back(a)
it = l.cbegin()
while it != l.cend():
a = deref(it)
incr(it)
print(a)
finally:
del l
def reverse_iteration_test(L):
"""
>>> reverse_iteration_test([1,2,4,8])
......@@ -106,6 +126,13 @@ cdef list to_pylist(cpp_list[int]& l):
incr(it)
return L
cdef list const_to_pylist(cpp_list[int]& l):
cdef list L = []
it = l.cbegin()
while it != l.cend():
L.append(deref(it))
incr(it)
return L
def item_ptr_test(L, int x):
"""
......@@ -117,6 +144,16 @@ def item_ptr_test(L, int x):
li_ptr[0] = x
return to_pylist(l)
def const_item_ptr_test(L, int x):
"""
>>> item_ptr_test(range(10), 100)
[100, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
cdef cpp_list[int] l = L
cdef int* li_ptr = &l.front()
li_ptr[0] = x
return const_to_pylist(l)
def test_value_type(x):
"""
>>> test_value_type(2)
......
......@@ -30,6 +30,18 @@ def test_map_insert_it(vals):
m.insert(um.begin(), um.end())
return [ (item.first, item.second) for item in m ]
def test_const_map_insert_it(vals):
"""
>>> test_const_map_insert_it([(1,1),(2,2),(2,2),(3,3),(-1,-1)])
[(-1, -1), (1, 1), (2, 2), (3, 3)]
"""
cdef unordered_map[int,int] um = unordered_map[int,int]()
cdef map[int,int] m = map[int,int]()
for k, v in vals:
um.insert(pair[int,int](k, v))
m.insert(um.cbegin(), um.cend())
return [ (item.first, item.second) for item in m ]
def test_map_count(vals, to_find):
"""
>>> test_map_count([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 1)
......@@ -95,6 +107,18 @@ def test_unordered_map_insert_it(vals):
um.insert(m.begin(), m.end())
return sorted([ (item.first, item.second) for item in um ])
def test_const_unordered_map_insert_it(vals):
"""
>>> test_const_unordered_map_insert_it([(1,1),(2,2),(2,2),(3,3),(-1,-1)])
[(-1, -1), (1, 1), (2, 2), (3, 3)]
"""
cdef map[int,int] m = map[int,int]()
cdef unordered_map[int,int] um = unordered_map[int,int]()
for v in vals:
m.insert(v)
um.insert(m.cbegin(), m.cend())
return sorted([ (item.first, item.second) for item in um ])
def test_unordered_map_count(vals, to_find):
"""
>>> test_unordered_map_count([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 1)
......
......@@ -30,6 +30,18 @@ def test_multimap_insert_it(vals):
mm.insert(umm.begin(), umm.end())
return [ (item.first, item.second) for item in mm ]
def test_const_multimap_insert_it(vals):
"""
>>> test_const_multimap_insert_it([(1,1),(2,2),(2,2),(3,3),(-1,-1)])
[(-1, -1), (1, 1), (2, 2), (2, 2), (3, 3)]
"""
cdef unordered_multimap[int,int] umm = unordered_multimap[int,int]()
cdef multimap[int,int] mm = multimap[int,int]()
for k, v in vals:
umm.insert(pair[int,int](k, v))
mm.insert(umm.cbegin(), umm.cend())
return [ (item.first, item.second) for item in mm ]
def test_multimap_count(vals, to_find):
"""
>>> test_multimap_count([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 1)
......@@ -94,6 +106,18 @@ def test_unordered_multimap_insert_it(vals):
umm.insert(mm.begin(), mm.end())
return sorted([ (item.first, item.second) for item in umm ])
def test_const_unordered_multimap_insert_it(vals):
"""
>>> test_const_unordered_multimap_insert_it([(1,1),(2,2),(2,2),(3,3),(-1,-1)])
[(-1, -1), (1, 1), (2, 2), (2, 2), (3, 3)]
"""
cdef multimap[int,int] mm = multimap[int,int]()
cdef unordered_multimap[int,int] umm = unordered_multimap[int,int]()
for v in vals:
mm.insert(v)
umm.insert(mm.cbegin(), mm.cend())
return sorted([ (item.first, item.second) for item in umm ])
def test_unordered_multimap_count(vals, to_find):
"""
>>> test_unordered_multimap_count([(1,1),(2,2),(2,2),(3,3),(-1,-1)], 1)
......
......@@ -29,6 +29,18 @@ def test_multiset_insert_it(vals):
ms.insert(ums.begin(), ums.end())
return [ item for item in ms ]
def test_const_multiset_insert_it(vals):
"""
>>> test_const_multiset_insert_it([1,2,2,3, -1])
[-1, 1, 2, 2, 3]
"""
cdef unordered_multiset[int] ums = unordered_multiset[int]()
cdef multiset[int] ms = multiset[int]()
for v in vals:
ums.insert(v)
ms.insert(ums.cbegin(), ums.cend())
return [ item for item in ms ]
def test_multiset_count(vals, to_find):
"""
>>> test_multiset_count([1,2,2,3, -1], 1)
......@@ -94,6 +106,18 @@ def test_unordered_multiset_insert_it(vals):
ums.insert(ms.begin(), ms.end())
return sorted([ item for item in ums ])
def test_const_unordered_multiset_insert_it(vals):
"""
>>> test_const_unordered_multiset_insert_it([1,2,2,3, -1])
[-1, 1, 2, 2, 3]
"""
cdef multiset[int] ms = multiset[int]()
cdef unordered_multiset[int] ums = unordered_multiset[int]()
for v in vals:
ms.insert(v)
ums.insert(ms.cbegin(), ms.cend())
return sorted([ item for item in ums ])
def test_unordered_multiset_count(vals, to_find):
"""
>>> test_unordered_multiset_count([1,2,2,3, -1], 1)
......
......@@ -30,6 +30,18 @@ def test_set_insert_it(vals):
s.insert(us.begin(), us.end())
return [item for item in s]
def test_const_set_insert_it(vals):
"""
>>> test_const_set_insert_it([1,2,2,3, -1])
[-1, 1, 2, 3]
"""
cdef unordered_set[int] us = unordered_set[int]()
cdef set[int] s = set[int]()
for v in vals:
us.insert(v)
s.insert(us.cbegin(), us.cend())
return [item for item in s]
def test_set_count(vals, to_find):
"""
>>> test_set_count([1,2,2,3, -1], 1)
......@@ -95,6 +107,18 @@ def test_unordered_set_insert_it(vals):
us.insert(s.begin(), s.end())
return sorted([item for item in us])
def test_const_unordered_set_insert_it(vals):
"""
>>> test_const_unordered_set_insert_it([1,2,2,3, -1])
[-1, 1, 2, 3]
"""
cdef set[int] s = set[int]()
cdef unordered_set[int] us = unordered_set[int]()
for v in vals:
s.insert(v)
us.insert(s.cbegin(), s.cend())
return sorted([item for item in us])
def test_unordered_set_count(vals, to_find):
"""
>>> test_unordered_set_count([1,2,2,3, -1], 1)
......
......@@ -92,6 +92,26 @@ def iteration_test(L):
finally:
del v
def const_iteration_test(L):
"""
>>> const_iteration_test([1,2,4,8])
1
2
4
8
"""
v = new vector[int]()
try:
for a in L:
v.push_back(a)
it = v.cbegin()
while it != v.cend():
a = d(it)
incr(it)
print(a)
finally:
del v
def reverse_iteration_test(L):
"""
>>> reverse_iteration_test([1,2,4,8])
......
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