title: Using a CwiseUnaryOp as an lvalue
body: <p>I'm using Eigen's EIGEN_MATRIXBASE_PLUGIN functionality to implement a CwiseUnary expression and I'm having trouble working out to extend this work with operator=</p>
  
  <p>I'm working with a struct that has two members: .val_ and .d_, and I've added a CwiseUnaryOp to access those:</p>
  
  <pre><code>template&lt;typename T&gt;
  struct d_Op {
    EIGEN_EMPTY_STRUCT_CTOR(d_Op)
    typedef T result_type;
    EIGEN_DEVICE_FUNC
    EIGEN_STRONG_INLINE const result_type&amp; 
      operator()(const stan::math::fvar&lt;T&gt; &amp;v) const { return v.d_; }
  };
  
  template&lt;typename T&gt;
  struct val_Op {
    EIGEN_EMPTY_STRUCT_CTOR(val_Op)
    typedef T result_type;
    EIGEN_DEVICE_FUNC
    EIGEN_STRONG_INLINE const result_type&amp; 
      operator()(const stan::math::fvar&lt;T&gt; &amp;v) const { return v.val_; }
  };
  
  inline const CwiseUnaryOp&lt;d_Op&lt;typename stan::partials_type&lt;Scalar&gt;::type&gt;, const Derived&gt;
  d_() const { return CwiseUnaryOp&lt;d_Op&lt;typename stan::partials_type&lt;Scalar&gt;::type&gt;,
                                   const Derived&gt;
      (derived(), d_Op&lt;typename stan::partials_type&lt;Scalar&gt;::type&gt;());
  }
  
  inline const CwiseUnaryOp&lt;val_Op&lt;typename stan::partials_type&lt;Scalar&gt;::type&gt;, const Derived&gt;
  val_() const { return CwiseUnaryOp&lt;val_Op&lt;typename stan::partials_type&lt;Scalar&gt;::type&gt;,
                                   const Derived&gt;
      (derived(), val_Op&lt;typename stan::partials_type&lt;Scalar&gt;::type&gt;());
  }
  </code></pre>
  
  <p>Such that, given a matrix of type <code>Matrix&lt;stan::math::fvar&lt;double&gt;,-1,-1&gt; m</code>, I can simply write: <code>m.val_()</code>.</p>
  
  <p>This is all working fine, however I'd like to extend it to write to those values, rather than just reading them (i.e. <code>m.val_() = MatrixXD::Random(int,int)</code>). But I can't figure out how to overload the <code>=</code> operator, giving me errors like this:</p>
  
  <pre><code>test.cpp:30:14: error: no match for ‘operator=’ (operand types are ‘const 
  Eigen::CwiseUnaryOp&lt;Eigen::MatrixBase&lt;Eigen::Matrix&lt;stan::math::fvar&lt;double&gt;, 
  -1, -1&gt; &gt;::val_Op&lt;double&gt;, const Eigen::Matrix&lt;stan::math::fvar&lt;double&gt;, -1, -1&gt; &gt;’ 
  and ‘Eigen::MatrixXd’ {aka ‘Eigen::Matrix&lt;double, -1, -1&gt;’})
  </code></pre>
  
  <p>Am I missing something very obvious here?</p>
  
  <p>EDIT: Output when using CwiseUnaryView instead:</p>
  
  <pre><code>test.cpp:30:14: error: no match for ‘operator=’ 
  (operand types are ‘const Eigen::CwiseUnaryView&lt;Eigen::MatrixBase&lt;Eigen::Matrix&lt;stan::math::fvar&lt;double&gt;, -1, -1&gt; &gt;::val_Op&lt;double&gt;, const Eigen::Matrix&lt;stan::math::fvar&lt;double&gt;, -1, -1&gt; &gt;’ 
  and ‘Eigen::MatrixXd’ {aka ‘Eigen::Matrix&lt;double, -1, -1&gt;’})
     a.val_() = inp;
  </code></pre>