Workaround for being unable to use initializer lists with unique_ptr?
<p>I'd like to have an array of polymorphic types that is generated at compile-time. Access into the array is dictated at runtime (otherwise I would just use a tuple). I would like the array to own its elements through a unique_ptr. Currently I'm using variadic templates to create the array. A simplified version of what I'm trying to do (MSVC 2012 November CTP):</p>

<pre><code>#include "stdafx.h"
#include &lt;array&gt;
#include &lt;memory&gt;
#include &lt;tuple&gt;
#include &lt;initializer_list&gt;
#include &lt;iostream&gt;

using namespace std;

class foo { };
class bar : public foo { };
class wiz : public foo { };

struct house
{
    template&lt;class... args&gt;
    struct furniture
    {
        typedef tuple&lt;args...&gt; t;

        static std::array&lt;unique_ptr&lt;foo&gt;, tuple_size&lt;t&gt;::value&gt; make()
        {
            std::array&lt;unique_ptr&lt;foo&gt;, tuple_size&lt;t&gt;::value&gt; l = { unique_ptr&lt;args&gt;(new args())... }; 
            return l;
        }
    };

    typedef furniture&lt;bar, wiz&gt; td;
};

int _tmain(int argc, _TCHAR* argv[])
{
    auto result = house::td::make();

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

<p>Unfortunately, I'm greeted with the compiler error:</p>

<pre><code>error C2248: 'std::unique_ptr&lt;foo,std::default_delete&lt;_Ty&gt;&gt;::unique_ptr' : cannot access private member declared in class 'std::unique_ptr&lt;foo,std::default_delete&lt;_Ty&gt;&gt;'
</code></pre>

<p>This is because initializer lists work through copies, but unique_ptr is not copyable. I can work around this by using shared_ptr (or raw pointers), which provides the behavior I want, but I'm curious if there's a way to create an array of unique_ptr like this. I'm still trying to wrap my head around variadic templates.</p>
