2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-29 19:52:16 +00:00

Add a small set of test cases for slice::get_indicies().

Promote slice::start(), slice::stop(), slice::step, and
slice::get_indicies() to const.
Fix typos in the documentation.


[SVN r23408]
This commit is contained in:
Jonathan Brandmeyer
2004-07-08 17:29:51 +00:00
parent 44e9ffc5ca
commit 8469d7727d
5 changed files with 66 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
#include <boost/python.hpp>
#include <boost/python/slice.hpp>
#include <vector>
using namespace boost::python;
@@ -75,9 +76,37 @@ bool check_numeric_array_rich_slice()
// Verify functions accepting a slice argument can be called
bool accept_slice( slice) { return true; }
int check_slice_get_indicies(const slice index)
{
// A vector of integers from [-5, 5].
std::vector<int> coll(11);
typedef std::vector<int>::iterator coll_iterator;
for (coll_iterator i = coll.begin(); i != coll.end(); ++i) {
*i = i - coll.begin() - 5;
}
slice::range<std::vector<int>::iterator> bounds;
try {
bounds = index.get_indicies<>(coll.begin(), coll.end());
}
catch (std::invalid_argument) {
return 0;
}
int sum = 0;
while (bounds.start != bounds.stop) {
sum += *bounds.start;
std::advance( bounds.start, bounds.step);
}
sum += *bounds.start;
return sum;
}
BOOST_PYTHON_MODULE(slice_ext)
{
def( "accept_slice", accept_slice);
def( "check_numeric_array_rich_slice", check_numeric_array_rich_slice);
def( "check_string_rich_slice", check_string_rich_slice);
def( "check_slice_get_indicies", check_slice_get_indicies);
}