
4 Dec
2011
4 Dec
'11
5:14 p.m.
Olaf van der Spek wrote:
On Sun, Dec 4, 2011 at 5:46 PM, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> 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.