How do I access a Tuple like an Array (with bracket overload and type safety)?
<p>I am trying to build a Tuple class that can be accessed like an Array. I could probably turn things into (void *) but that would defeat the purpose of the templates since I'm trying to get type-safety.</p>

<p>I'm compiling using VS2010 pro. My current non-working solution produces the following error. </p>

<p>Error: 'Item &amp;MyList::operator ' : could not deduce template argument for 'N'.</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;tuple&gt;
#include &lt;stdio.h&gt;

template &lt;int size, typename Ty0, 
typename Ty1=std::tr1::_Nil, typename Ty2=std::tr1::_Nil, typename Ty3=std::tr1::_Nil,
typename Ty4=std::tr1::_Nil, typename Ty5=std::tr1::_Nil, typename Ty6=std::tr1::_Nil, 
typename Ty7=std::tr1::_Nil, typename Ty8=std::tr1::_Nil, typename Ty9=std::tr1::_Nil&gt;
struct MyList {
    std::tuple&lt;Ty0, Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7, Ty8, Ty9&gt; items;

    template &lt;int N, typename Ty&gt;
    Ty &amp;operator[](int N) {
        auto &amp;var = std::get&lt;N&gt;(items);
        return var;
    }
};

void main() {
    MyList&lt;2, int, double&gt; list;
    auto var = list[0];
}
</code></pre>

<p><b>Potential Solutions: (edit)</b></p>

<ol>
<li><a href="http://cpptruths.blogspot.com/2012/01/array-like-access-and-iterators-for.html" rel="nofollow">Variadic templates with homogeneous data</a></li>
<li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3413.html" rel="nofollow">Using constexpr C++11</a></li>
</ol>
