<p>In C++0x I would like to write a function like this:</p>

<pre><code>template &lt;typename... Types&gt;
void fun(typename std::tuple&lt;Types...&gt; my_tuple) {
    //Put things into the tuple
}
</code></pre>

<p>I first tried to use a for loop on <code>int i</code> and then do:</p>

<pre><code>get&lt;i&gt;(my_tuple);
</code></pre>

<p>And then store some value in the result. However, <code>get</code> only works on <code>constexpr</code>.</p>

<p>If I could get the variables out of the <code>tuple</code> and pass them to a variadic templated function I could recurse through the arguments very easily, but I have no idea how to get the variables out of the tuple without <code>get</code>. Any ideas on how to do that? Or does anyone have another way of modifying this <code>tuple</code>?</p>

[{'answer_id': 80573, 'author': 'Adam Mitz', 'author_id': 2574, 'author_profile': 'https://Stackoverflow.com/users/2574', 'pm_score': 3, 'selected': True, 'text': '<p>Since the "i" in</p>\n\n<pre><code>get&lt;i&gt;(tup)\n</code></pre>\n\n<p>needs to be a compile-time constant, template instantiation is used to "iterate" (actually recurse) through the values.  Boost tuples have the "length" and "element" meta-functions that can be helpful here -- I assume C++0x has these too.</p>\n'}, {'answer_id': 80687, 'author': 'Daniel James', 'author_id': 2434, 'author_profile': 'https://Stackoverflow.com/users/2434', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.boost.org/doc/libs/release/libs/fusion/doc/html/index.html" rel="nofollow noreferrer">Boost.Fusion</a> is worth a look. It can \'iterate\' over <code>std::pair</code>, <code>boost::tuple</code>, some  other containers and its own tuple types, although I don\'t think it supports <code>std::tuple</code> yet.</p>\n'}, {'answer_id': 103372, 'author': 'Timmie Smith', 'author_id': 8405, 'author_profile': 'https://Stackoverflow.com/users/8405', 'pm_score': 0, 'selected': False, 'text': '<p>Take a look at section 6.1.3.4 of TR1, <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf" rel="nofollow noreferrer">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf</a></p>\n\n<p>get is defined for both const and non-const qualified tuples and returns the appropriate reference type.  If you change your function declaration to the following:</p>\n\n<pre><code>template \nvoid fun(typename std::tuple& my_tuple) {\n    //Put things into the tuple\n}</code></pre>\n\n<p>Then the argument to your function is a non-const tuple and get will allow you to make the necessary assignments once you\'ve written the iteration using the information provided in previous responses.</p>\n'}, {'answer_id': 103401, 'author': 'DrPizza', 'author_id': 2131, 'author_profile': 'https://Stackoverflow.com/users/2131', 'pm_score': 0, 'selected': False, 'text': "<p>AFAICT, C++ tuples basically need to be handled with recursion; there don't seem to be any real ways of packing/unpacking tuples <em>except</em> using the typesystem's only variadic template handling.</p>\n"}, {'answer_id': 1611301, 'author': 'David', 'author_id': 193481, 'author_profile': 'https://Stackoverflow.com/users/193481', 'pm_score': 0, 'selected': False, 'text': '<p>Have a look at my answer here for an example of template recursion to unwind tuple arguments to a function call.</p>\n\n<p><a href="https://stackoverflow.com/questions/687490/c0x-how-do-i-expand-a-tuple-into-variadic-template-function-arguments">How do I expand a tuple into variadic template function&#39;s arguments?</a></p>\n'}]
['https://Stackoverflow.com/questions/80348', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']