Boost logo

Boost :

Subject: Re: [boost] [smart-ptr][containers] type of the operator[] index
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2011-12-04 13:15:46


Le 04/12/11 18:14, Peter Dimov a écrit :
> Olaf van der Spek wrote:
>> On Sun, Dec 4, 2011 at 5:46 PM, Vicente J. Botet Escriba
>> <vicente.botet_at_[hidden]> wrote:
>> > which is the correct type used as index of operator[]. scoped_array
>> uses
>> > std::ptrdiff_t. Others containers use std::size_t.
>>
>> If [-1] might be valid, ptrdiff_t makes sense. Otherwise, I'd opt for
>> size_t.
>
> -1 doesn't make sense for scoped_array. It uses ptrdiff_t in order to
> assert that the index is nonnegative. Other containers, knowing its
> size, need not use ptrdiff_t because assert( index < size ) will fire
> when the index is (size_t)-1.
>
So which will be the type used to to move from a scoped_array to another
container?

Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk