Commit 34c96391 authored by gbalduzz's avatar gbalduzz
Browse files

Add support for range based loop in functions.

parent a13291c9
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -115,6 +115,20 @@ public:
    return size_sbdm[index];
  }

  // Begin and end methods for compatibility with range for loop.
  scalartype* begin() {
    return fnc_values;
  }
  scalartype* end() {
    return fnc_values + Nb_elements;
  }
  const scalartype* begin() const {
    return fnc_values;
  }
  const scalartype* end() const {
    return fnc_values + Nb_elements;
  }

  // Returns a pointer to the function's elements.
  scalartype* values() {
    return fnc_values;
+13 −0
Original line number Diff line number Diff line
@@ -646,3 +646,16 @@ TEST(FunctionTest, MemoryLayout) {
        ++count;
      }
}

TEST(FunctionTest, RangeBasedLoop) {
  using Dmn = dmn_variadic<dmn_0<dmn<5>>, dmn_0<dmn<7>>>;

  dca::func::function<float, Dmn> f;

  int i = 0;
  for (auto& x : f)
    x = i++;

  for (int i = 0; i < f.size(); ++i)
    EXPECT_EQ(i, f(i));
}