[llvm-commits] implement and use SmallVector::data()

Chris Lattner clattner at apple.com
Wed May 20 13:35:08 PDT 2009


On May 20, 2009, at 3:34 AM, Jay Foad wrote:

> SmallVector::operator[] has this comment:
>
>  /* These asserts could be "Begin + idx < End", but there are lots  
> of places
>     in llvm where we use &v[v.size()] instead of v.end(). */
>  reference operator[](unsigned idx) {
>    assert (Begin + idx <= End);
>    return Begin[idx];
>  }
>  const_reference operator[](unsigned idx) const {
>    assert (Begin + idx <= End);
>    return Begin[idx];
>  }
>
> I think this is a bit ugly, and rather non-standard, because it means
> SmallVector behaves differently from std::vector.
>
> The attached patch adds a data() method to SmallVector, following DR  
> 464:
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#464
>
> ... and tightens up the asserts in operator[], and converts code like
> "foo(&vec[0], vec.size())" to "foo(vec.data(), vec.size())" when it
> was triggering the assert. It passes "make check" and cfe's "make
> test", and llvm-gcc still bootstraps.

Looks nice to me, please apply!

-Chris



More information about the llvm-commits mailing list