Jason House wrote:
void iterateOverArray(T)(T[] arr){
  foreach (i; 0..arr.length)
    yield(arr[i]);
}

Coroutines are the slowest option, but the easiest to write. It takes 32 instructions or so to switch to or from a coroutine on x86. I'm not sure how that translates in terms of memory usage, though. A delegate is reasonably fast. A range struct's methods can be inlined (though opApply could be, too, in some cases).

However, any collection library using polymorphism will have to use polymorphic iterators. This means you probably won't get any benefit in terms of speed from using ranges -- quite the opposite. But there are benefits.

Reply via email to