diff --git a/tools/python/src/basic.cpp b/tools/python/src/basic.cpp index 84e10a15a..786355b6c 100644 --- a/tools/python/src/basic.cpp +++ b/tools/python/src/basic.cpp @@ -140,6 +140,14 @@ string sparse_vector__repr__ (const std::vector return sout.str(); } +unsigned long range_len(const std::pair& r) +{ + if (r.second > r.first) + return r.second-r.first; + else + return 0; +} + template void resize(T& v, unsigned long n) { v.resize(n); } @@ -174,11 +182,12 @@ void bind_basic_types() typedef pair range_type; class_("range", "This object is used to represent a range of elements in an array.", init<>() ) .def(init()) - .def_readwrite("begin",&range_type::first, "The index of the first element in the range.") - .def_readwrite("end",&range_type::second, "One past the index of the last element in the range.") + .def_readwrite("begin",&range_type::first, "The index of the first element in the range. This is represented using an unsigned integer.") + .def_readwrite("end",&range_type::second, "One past the index of the last element in the range. This is represented using an unsigned integer.") .def("__str__", range__str__) .def("__repr__", range__repr__) .def("__iter__", &make_range_iterator) + .def("__len__", &range_len) .def_pickle(serialize_pickle()); class_("_range_iter")