c++ Cast a vector of unique_ptr<Base> to unique_ptr<Derived> where derived is a template <p>I have the following situation:</p> <p><code>Base</code> is a base class. <code>T</code> is a template that can assume any derived class of <code>Base</code>.</p> <p>The underlying layer provide me data from <code>Base</code> class, that I need to convert to a specific class on the above layer (that layer where the code is written) to work on a user level.</p> <p>Here is the code:</p> <pre><code>template &lt;class T&gt; class Access { std::vector&lt;std::unique_ptr&lt;T&gt; getData(); } template &lt;class T&gt; std::vector&lt;std::unique_ptr&lt;T&gt; getData() { /// Get data from below layer std::vector&lt;std::unique_ptr&lt;Base&gt;&gt; retData; retData = getDataFromBelowLayer(); /// Now I have to cast Base to T std::vector&lt;std::unique_ptr&lt;T&gt;&gt; retCastData; for (auto &amp;item : retData) { std::unique_ptr&lt;T&gt; = static_cast&lt;T&gt;(item); &lt;&lt;---- NOT WORKING retCastData.push_back(std::move(item)); &lt;&lt;---- NOT WORKING } return retCastData; } </code></pre> <p>How can I efficiently cast the <code>vector</code> of <code>unique_ptr´s</code> of <code>Base</code> class received to the <code>vector</code> of <code>unique_ptr´s</code> of <code>T</code> type as shown.</p> <p>Thanks for helping.</p>