
Bo Persson wrote:
:: &a[0]; :: :: The C++ community promotes std::vector as a C array replacement, :: but :: it's really not because it's not legal to do the above operation :: when :: the vector is empty.
That's just a misuse of the std::vector. You never, ever get the idea of taking the address of an empty array. Why attempt that on an empty vector??
Dunno what you mean by "get the idea of taking the address," but this is a perfectly reasonable thing to do in C. In llvm, there are many interfaces that want, for example: foo(int *array, int num) It's perfectly legal to pass (&a[0], 0) to that. It is not legal if a is a std::vector, however. That's why std::vector is not a replacement for a C array. Yet it is touted as such by C++ proponents. We need to be much more precise in our advocacy.
:: I believe this is because the vector :: interface :: is characterized in terms of iterators rather than addresses.
Yes, so a.begin() works even for an empty vector. Why is the address so interesting?
Because it's the whole point of my message. The pointer interfaces do cause some problems. I'm slowly converting these to take iterators instead. I have to respectfully disagree with Chris. The problem isn't iterators _per_se_, it's the pointer interface the iterators are used with that causes the problems. Converting to these interfaces to iterators in turn drives a conversion to use templated interfaces and this is something the llvm community has been open to, to its credit. -Dave