On 2014-10-06, 11:20 AM, Trevor Saunders wrote:
Hence, I suggest for cases like this, |auto| should be a recommendation.
IIRC, it is one of the cases that |auto| was introduced for.
For cases like:
for (int32_t i = 0; i < array.Length(); i++)
I even want to write it as
for (decltype(array.Length()) i = 0; i < array.Length(); i++)
but I feel it too redundant. I hope C++ could support
for (auto iend = array.Length(), i = 0; i < iend; i++)
but, unfortunately, it does not.
Do you think this case reasonable?
Your request is very reasonable, but as you note, it's not possible in C++.
C++'s answer to this is "ranged-based for loops"
<http://en.wikipedia.org/wiki/C%2B%2B11#Range-based_for_loop> which in my
experience are *super* nice. They let you iterate over the array like this:
I'll certainly grant they look nice, but I'm worried they obscure what
happens in case of mutation, and we already have plenty of exploitable
bugs about that.
The usage of the iterator object which can also store state allows you
to check for that exact pattern, so arguably you won't lose anything
using range-based for loops if we added a good iterator implementation
to nsTArray that checks for mutations.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform