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

Joel de Guzman djowel at gmx.co.uk
Tue Sep 30 01:08:18 CEST 2003


Raoul Gough <RaoulGough at yahoo.co.uk> wrote:
> "Joel de Guzman" <djowel at gmx.co.uk> writes:
> 
>> Mike Thompson <mike.thompson at day8.com.au> wrote:
> [snip]
>>> 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.

I *was* using PySlice_GetIndices. The problem was (if I'm not mistaken),
is that it does not handle non-integer inteces. Correct me if I'm wrong.
For example, I have a case where the indexes are dates that I must convert
to a valid index.

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net






More information about the Cplusplus-sig mailing list