Matrix.opApply

Iterates matrix returning line and column number with element.

  1. int opApply(int delegate(ref Type) foreach_)
  2. int opApply(int delegate(ref size_t, ref Type) foreach_)
  3. int opApply(int delegate(ref size_t, ref size_t, ref Type) foreach_)
    struct Matrix(size_t Lines, size_t Cols, Type = float)
    @trusted
    int
    opApply
    (
    int delegate
    (
    ref size_t
    ,
    ref size_t
    ,
    ref Type
    )
    foreach_
    )
    if (
    Lines > 0 &&
    Cols > 0
    )

Examples

{
      auto m = Matrix3i
      (
           3, -1, 6,
           2,  1, 5,
          -3,  1, 0
      );

      // Let's iterate matrix by element number
      size_t index;
      foreach (i, ref element; m)
      {
          if (element == 5)
          {
              index = i;
              break;
          }
      }
      assert (index == 5);

      // Let's iterate matrix with line and column number
      size_t line, col;
      foreach (i, j, ref element; m)
      {
          if (element == 5)
          {
              line = i;
              col = j;
              break;
          }
      }
      assert (line == 1 && col == 2);

Meta