[C++-sig] Extensible slice support in new indexing suite

Raoul Gough RaoulGough at yahoo.co.uk
Tue Oct 14 17:20:42 CEST 2003


After some offline disucssion with Joel de Guzman, I've made slice
support configurable in the new indexing suite (it was already
configurable in the original suite). This is designed to support
client-code extensions for slices with non-integer index types.

Here's an overview of how it works: there is an indexing::slice class,
which is registered for automatic conversion from PySlice_Type
objects. The code that actually extracts the indexes from the Python
object is separated into a new indexing::integer_slice class, which
take the plain slice for construction. Client code can now select an
alternative implementation intead of integer_slice as follows.

The slice_handler template relies on a typedef "slice_helper" and
factory function "make_slice_helper" provided by its Algorithms
argument. The only existing implementation is int_slice_helper, which
inter-operates with the integer_slice class, or anything else which
can provide similar start, stop, step and in_range functions. For the
sort of cases Joel and I were discussing, I would expect
int_slice_helper to be sufficiently generic so you would only have to
provide a new class to extract the bounds from the Python slice object
(i.e. a new version of integer_slice) and override the typedef and the
factory function.  Other cases, like slices in a std::map, would
probably require a complete new slice_helper, e.g. an
iterator_slice_helper.

BTW, I've also added support for overriding basic support functions in
the algorithms templates like begin() and end() using the curiously
recurring template idiom. However, that's unrelated to the slice
extensions - hopefully it won't confuse the issue too much.

I'll get started on proper documentation for all this sometime
soonish, but if anyone has comments on the code already, please let me
know.

-- 
Raoul Gough.
(setq dabbrev-case-fold-search nil)





More information about the Cplusplus-sig mailing list