I asked a question in #developers that what is the best way to reversely
iterating nsTArray, and there are some suggestions:

<tbsaunde> uint32_t count = array.Length(); for (uint32_t i = length - 1; i
< length; i--)
<smaug> iterate from length() to 1 and index using i - 1
<jcranmer> for (uint32_t i = array.Length(); i-- > 0; ) { }

tbsaunde's method should work fine, but not intuitive. smaug's looks fine
to me, but could cause some problem if I use i instead of i-1 by mistake.
jcranmer's... I don't think it is a good idea, anyway. None of them looks
prefect to me.


As we have supported range-based for loop in our code, I purpose that we
have something like ReverseIntegerRange, and use this with range-based loop
to iterate the index. So we can use, for example: for (auto i :
ReverseIntegerRange(array.Length()))

Maybe we can also add IntegerRange to benefit from the integer type
dedution.

How does it sound?

- Xidorn
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to