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:17:46

Le 04/12/11 18:02, Andrey Semashev a écrit :
> On Sunday, December 04, 2011 17:46:02 Vicente J. Botet Escriba wrote:
>> Hi,
>> which is the correct type used as index of operator[]. scoped_array uses
>> std::ptrdiff_t. Others containers use std::size_t.
>> When using an index to move from a scoped_array to another container
>> which should be the type if the index?
> In containers, there isn't any sense in negative indices since they are always
> relative to the beginning of the container (and there isn't any elements
> before the beginning). This is not true for pointers or iterators since a
> pointer may refer to an element in the midst of a valid range.
> Smart pointers might depart from raw pointers in this regard because they also
> tend to point to the beginning of the range. But as I see it, they also accept
> ptrdiff_t to be as close to raw pointers as possible.
Scoped_array can not take a pointer in the middle of the allocated array
as its role is to delete it.


Boost list run by bdawes at, gregod at, cpdaniel at, john at