[C++-sig] Re: vector_indexing_suite too defensive ...

Raoul Gough RaoulGough at yahoo.co.uk
Mon Sep 29 16:46:32 CEST 2003

"Joel de Guzman" <djowel at gmx.co.uk> writes:

> Mike Thompson <mike.thompson at day8.com.au> wrote:
>> The IndexError arises because vector_indexing_suite defends against
>> an slice index being too big, rather than the python list approach
>> which regards a slice index > len(L) as equal to len(L).  So, the
>> line of padOrChop() which says:
>>     lst[size:] = [padValue] * diff
>> causes an exception when size > len(lst).
>> Should vector_indexing_suite be altered to give behaviour more like
>> that of lists in this regard?
> It should. I think you uncovered a vector_indexing_suite bug. I'll
> correct this as soon as I can.

Hi Joel,

You might find the PySlice_GetIndices function useful - it take a
Python slice object and a container length and returns normalized
start and stop values (even handling negative indices, IIRC). At a
guess, this is probably how the Python list works internally too.

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

More information about the Cplusplus-sig mailing list