[C++-sig] Rational for 'Zero-length slice' RuntimeError?

Hans Meine meine at informatik.uni-hamburg.de
Sun Jan 4 21:21:20 CET 2009


I have exported an array-like class using the __getitem__ implementation given 
below among its overloads.  It uses boost::python::slice.get_indices(), and I 
am getting a RuntimeError when I try to acces e.g. [1:-1] on a 2-element 
array.  What is the rationale for this "Zero-length slice" error?  I would 
expect an empty iterator range.  OK, if end < begin, that could make 
problems, but what am I expected to do to prevent this RuntimeError?
(Yes, I did RTFM, but maybe I am overlooking something?)

template<class Array>
Array__getitem_slice__(Array const & a, boost::python::slice sl)
    boost::python::slice::range<typename Array::const_iterator>
        bounds = sl.template get_indicies<>(a.begin(), a.end());

    if(bounds.step != 1)
                        "No extended slicing supported yet.");

    return std::auto_ptr<Array>(new Array(bounds.start, bounds.stop+1));

Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090104/859e6073/attachment.pgp>

More information about the Cplusplus-sig mailing list