Boost logo

Boost :

Subject: Re: [boost] [smart-ptr][containers] type of the operator[] index
From: Peter Dimov (pdimov_at_[hidden])
Date: 2011-12-04 12:14:48


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.


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