invalid initialization of non-const reference of type from an rvalue of type for arma::subvec
<p>The vector <code>y_long_name</code> has 100 members and I plan to manipulate only a subvector of it made of first three members. The <code>subvector</code> function is used in my code like a left value:</p>

<pre><code>y_long_name.subvec(0,2)=A*x1;
</code></pre>

<p>However C++ does not recognize it as a left value. How can I define <code>yr</code> to be used instead of <code>y_long_name.subvec(0,2)</code>?</p>

<p>what I want to do is to use the short form <code>yr</code> instead of <code>y_long_name.subvec(0,2)</code> but without using macro.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;armadillo&gt;

int main()
{
    const arma::vec::fixed&lt;3&gt; x1={1.2,3.5,-0.27};   
    arma::mat::fixed&lt;3,3&gt; A={{5,3,6},{8,2,11},{7,5,9}};

    arma::vec::fixed&lt;3&gt; y1=A*x1; // ok

    arma::vec::fixed&lt;100&gt; y_long_name;
    y_long_name.subvec(0,2)=A*x1; // ok

    arma::vec::fixed&lt;3&gt;&amp; yr=y_long_name.subvec(0,2);
    yr=A*x1;

    y_long_name.print();

    return 0;
}
</code></pre>

<p>Error:</p>

<pre><code>test.cpp: In function ‘int main()’:
test.cpp:14:48: error: invalid initialization of non-const reference of type ‘arma::Col&lt;double&gt;::fixed&lt;3ull&gt;&amp;’ from an rvalue of type ‘arma::subview_col&lt;double&gt;’
  arma::vec::fixed&lt;3&gt;&amp; yr=y_long_name.subvec(0,2)
</code></pre>