On Tuesday, 26 July 2016 at 13:19:54 UTC, ag0aep6g wrote:
Operator precedence is different from what you think. `a ? b : c = d` means `(a ? b : c) = d`. But you want `a ? b : (c = d)`. So you need parentheses around `p+=1`.

Or just go with `if` and `else`. It's clearer anyway.

From http://wiki.dlang.org/Operator_precedence

Priority(15 is highest)
3                      Conditional operator                  ?:         
2 Assignment operators = -= += <<= >>= >>>= = *= %= ^= ^^= ~=

I was actually close to not needing parentheses :). But I see that your suggestion to stick with if else in this case is the sensible thing to do, especially since ?: seems to lead to more errors. Thanks for the answers.

Reply via email to