Why is indexed foreach restricted to build in array ?

Jakob Ovrum via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 11 06:01:33 PDT 2015


On Saturday, 11 April 2015 at 12:04:06 UTC, matovitch wrote:
> well ldc doesn't compile :
>
> kmeans.d(40): Error: no property 'enumerate' for type 'Range'
>
> With -O -release -inline  I get around 2s with foreach and 0.5s 
> with a simple for.

LDC does not yet support the 2.067 front-end version in which 
`enumerate` was made available. You could get the `enumerate` 
implementation from the DMD release and it should work with older 
FE versions (within reason - it may or may not depend on 
relatively new language features).

Performance with range-based code requires a sophisticated 
optimizer, the kind that is used to optimize idiomatic C++ code. 
In particular, inlining is important as there are a lot of tiny 
generic functions involved. Unfortunately, DMD's optimizer is not 
up to this task.


More information about the Digitalmars-d-learn mailing list