title: Extending Eigen with CWiseNullaryOp: Cannot reproduce example
body: <p>I am trying to reproduce the second example on <a href="http://eigen.tuxfamily.org/dox/TopicCustomizing_NullaryExpr.html" rel="nofollow noreferrer">this page</a> of the Eigen documentation, but cannot compile my minimal program. I am using Eigen 3.3~beta1-2.</p>
  
  <p>When running g++ with the following arguments <code>-std=c++11 -Wall -pipe -O3 -ffast-math -funsafe-math-optimizations -march=native -mtune=native -pedantic -Wno-unused-variable -I/usr/local/include/eigen3 -I/usr/include/eigen3 -c example.cpp</code>, I get this error:</p>
  
  <pre><code>example.cpp:8:41 ("Eigen::MatrixXi B = indexing(A, ri, ci)" in program below)  
  /usr/include/eigen3/Eigen/src/Core/CoreEvaluators.h:348:27: error: no match for call to '(const indexing_functor&lt;Eigen::Matrix&lt;int, -1, -1&gt;, Eigen::Array&lt;int, 3, 1&gt;, Eigen::Array&lt;int, -1, 1&gt; &gt;) (Eigen::Index&amp;)
        return m_functor(index);
  </code></pre>
  
  <p>My minimal program consists of the following (essentially copy and pasted from the example in the documentation):</p>
  
  <p><strong>example.h</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;Eigen/Core&gt;
  
  using namespace Eigen;
  
  template&lt;class ArgType, class RowIndexType, class ColIndexType&gt;
  class indexing_functor {
    const ArgType &amp;m_arg;
    const RowIndexType &amp;m_rowIndices;
    const ColIndexType &amp;m_colIndices;
  public:
    typedef Matrix&lt;typename ArgType::Scalar,
                   RowIndexType::SizeAtCompileTime,
                   ColIndexType::SizeAtCompileTime,
                   ArgType::Flags&amp;RowMajorBit?RowMajor:ColMajor,
                   RowIndexType::MaxSizeAtCompileTime,
                   ColIndexType::MaxSizeAtCompileTime&gt; MatrixType;
    indexing_functor(const ArgType&amp; arg, const RowIndexType&amp; row_indices, const ColIndexType&amp; col_indices)
      : m_arg(arg), m_rowIndices(row_indices), m_colIndices(col_indices)
    {}
    const typename ArgType::Scalar&amp; operator() (Index row, Index col) const {
      return m_arg(m_rowIndices[row], m_colIndices[col]);
    }
  };
  
  template &lt;class ArgType, class RowIndexType, class ColIndexType&gt;
  CwiseNullaryOp&lt;indexing_functor&lt;ArgType,RowIndexType,ColIndexType&gt;, typename indexing_functor&lt;ArgType,RowIndexType,ColIndexType&gt;::MatrixType&gt;
  indexing(const Eigen::MatrixBase&lt;ArgType&gt;&amp; arg, const RowIndexType&amp; row_indices, const ColIndexType&amp; col_indices)
  {
    typedef indexing_functor&lt;ArgType,RowIndexType,ColIndexType&gt; Func;
    typedef typename Func::MatrixType MatrixType;
    return MatrixType::NullaryExpr(row_indices.size(), col_indices.size(), Func(arg.derived(), row_indices, col_indices));
  }
  </code></pre>
  
  <p><strong>example.cpp</strong></p>
  
  <pre><code>#include "example.h"
  
  int main()
  {
    Eigen::MatrixXi A = Eigen::MatrixXi::Random(4,4);
    Array3i ri(1,2,1);
    ArrayXi ci(6); ci &lt;&lt; 3,2,1,0,0,2;
    Eigen::MatrixXi B = indexing(A, ri, ci);
    std::cout &lt;&lt; "A =" &lt;&lt; std::endl;
    std::cout &lt;&lt; A &lt;&lt; std::endl &lt;&lt; std::endl;
    std::cout &lt;&lt; "A([" &lt;&lt; ri.transpose() &lt;&lt; "], [" &lt;&lt; ci.transpose() &lt;&lt; "]) =" &lt;&lt; std::endl;
    std::cout &lt;&lt; B &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Am I missing something fundamental about how templates work in C++?</p>