<p>In <a href="https://github.com/mlpack/mlpack/pull/757#discussion_r74183802">src/mlpack/methods/ann/layer/concat_layer.hpp</a>:</p>
<pre style='color:#555'>&gt; +
&gt; +namespace mlpack {
&gt; +namespace ann /** Artificial Neural Network. */ {
&gt; +/**
&gt; + * @tparam JoinLayers Contains all layer modules that need be concatenated.
&gt; + */
&gt; +template &lt;typename JoinLayers,
&gt; +          typename InputDataType = arma::cube,
&gt; +          typename OutputDataType = arma::cube&gt;
&gt; +class ConcatLayer
&gt; +{
&gt; + public:
&gt; +  ConcatLayer(const size_t numLayers,
&gt; +              JoinLayers &amp;&amp;layers) :
&gt; +  numLayers(numLayers),
&gt; +  layers(std::forward&lt;JoinLayers&gt;(layers))
</pre>
<p>Your solution tell the compiler "JoinLayers must be rvalue", that means</p>

<pre><code>SomeLayer layers;
ConcatLayer&lt;SomeLayer&gt; ConcatLayer(layers);
</code></pre>

<p>Do not work, because layers is an lvalue in this case, but the constructor only accept rvalue.</p>

<p>If you want to perform perfect forwarding by std::forward(which means, if it is rvalue, cast it to rvalue, if it is lvalue, cast it lvalue), you need to write it as</p>

<pre><code>template&lt;typename JoinLayersType&gt;
ConcatLayer(const size_t numLayers,
                    JoinLayersType &amp;&amp;layers) ;
</code></pre>

<p>In this case, the compiler will treat JoinLayers&amp;&amp; as "<a href="https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers">universal reference</a>", so perfect forwarding work under this case.</p>

<p>You may ask, but I need the JoinLayersType == JoinLayers, use can use static_assert to add this restriction work</p>

<pre><code>using RawJLT = typename std::decay&lt;JoinLayersType &gt;::type;
static_assert(std::is_same&lt;RawJLT , JoinLayers&gt;::value, "type of JoinLayerType must equal to JoinLayers");
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/mlpack/mlpack/pull/757/files/06d923321f246f2c6ead9ad56e99309fe24a6f5c#r74183802">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJ4bFE9lntVT3fuyioiI7L45eN4Br3h_ks5qeVMbgaJpZM4JejWj">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFCGbsIXzgzxJAC-sD4KY4aOLGg_-ks5qeVMbgaJpZM4JejWj.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/pull/757/files/06d923321f246f2c6ead9ad56e99309fe24a6f5c#r74183802"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/mlpack/mlpack","title":"mlpack/mlpack","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/mlpack/mlpack"}},"updates":{"snippets":[{"icon":"PERSON","message":"@stereomatchingkiss in #757: Your solution tell the compiler \"JoinLayers must be rvalue\", that means\r\n\r\n```\r\nSomeLayer layers;\r\nConcatLayer\u003cSomeLayer\u003e ConcatLayer(layers);\r\n```\r\nDo not work, because layers is an lvalue in this case, but the constructor only accept rvalue.\r\n\r\nIf you want to perform perfect forwarding by std::forward(which means, if it is rvalue, cast it to rvalue, if it is lvalue, cast it lvalue), you need to write it as\r\n\r\n```\r\ntemplate\u003ctypename JoinLayersType\u003e\r\nConcatLayer(const size_t numLayers,\r\n                    JoinLayersType \u0026\u0026layers) ;\r\n```\r\nIn this case, the compiler will treat JoinLayers\u0026\u0026 as \"[universal reference](https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers)\", so perfect forwarding work under this case.\r\n\r\nYou may ask, but I need the JoinLayersType == JoinLayers, use can use static_assert to add this restriction work\r\n\r\n```\r\nusing RawJLT = typename std::decay\u003cJoinLayersType \u003e::type;\r\nstatic_assert(std::is_same\u003cRawJLT , JoinLayers\u003e::value, \"type of JoinLayerType must equal to JoinLayers\");\r\n```\r\n"}],"action":{"name":"View Pull Request","url":"https://github.com/mlpack/mlpack/pull/757/files/06d923321f246f2c6ead9ad56e99309fe24a6f5c#r74183802"}}}</script>