On Sunday, August 24, 2025 2:35:57 AM Mountain Daylight Time Per Nordlöw via Digitalmars-d-learn wrote: > Which are the pros and cons of foreach vs static foreach on a > compile time tuple in D in terms of compiler performance and > resource usage? Does static foreach generate more ast > duplications?
As I understand it, there should be no real difference in compile time performance between static foreach and a foreach being done at compile time. The main differences are that foreach introduces a new scope (whereas static foreach does not), that static foreach _must_ be done at compile time (whereas whether foreach is done at compile time depends on what you're iterating over), and that static foreach can be used in some contexts where foreach isn't legal (e.g. at module scope). So, if you're iterating over something like an AliasSeq within a function body, it really shouldn't matter which you use. - Jonathan M Davis