On Thursday, 5 July 2018 at 14:05:42 UTC, Seb wrote:
FYI: you can introduce scopes with static foreach to declare new variables:

for (int i = 0; i < 4 * n; i += 4)
{
    static foreach (k; 0..4)
    {{
       auto idx = i + k
       a[idx] += idx;
    }}
}

Thanks!  The two parentheses trick is nice.

Generally, I was reluctant to declare a variable because, well, micro-optimizing means being dissatisfied with compiler optimization. So the mindset didn't allow me to just go and declare a variable in the innermost loop, in fear that the optimizer might not optimize the allocation away.

Reply via email to