d - Is there a better way to iterate over multidimensional array? -


i have dynamic 3d array of numbers , i'm doing in c:

for (auto = 0; < size; i++) {     (auto j = 0; j < size; j++) {         (auto k = 0; k < size; k++) {             ...         }     } } 

looks pretty ugly. there shorter , maybe more "elegant" way of doing in d?

using foreach idiomatic approach in d. possible iterate both index , value or value only.

import std.stdio;  void main () {  auto arr3 = [ [[1 ,2 ,3 ]], [[4 ,5 ,6 ]], [[7 , 8, 9]],                [[11,12,13]], [[14,15,16]], [[17,18,19]] ];      foreach (index3, arr2; arr3)     foreach (index2, arr1; arr2)     foreach (index1, val ; arr1) {         assert (val == arr3[index3][index2][index1]);         writeln (val);     } } 

Comments

Popular posts from this blog

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -

jQuery clickable div with working mailto link inside -