Is prefix ++ preferred in D because of some specific reason? I recall it, for some containers/iterators, gives smaller/faster codegen in C++?

I assume the reason is the same as in C++. As users can provide their own implementations of pre and postfix incrementing, the compiler can't assume that x++ always means "copy x then increment x and return the copy". It could have arbitrary side effects. Therefore for user defined types x++ can't be replaced with ++x by the compiler even if you're not using the return value. The compiler _can_ do this for primitive types, but as monarch_dodra says, if you get in the habit of using ++x unless you explicitly need x++ then you're never going to suffer and can sometimes get a speed win.

Reply via email to