forked from boostorg/mp11
Fix tuple_cat example a bit
This commit is contained in:
@@ -474,7 +474,7 @@
|
||||
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="number">2</span><span class="special">></span> <span class="identifier">t1</span><span class="special">{</span> <span class="number">1</span><span class="special">,</span> <span class="number">2</span> <span class="special">};</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="keyword">float</span><span class="special">,</span> <span class="number">3</span><span class="special">></span> <span class="identifier">t2</span><span class="special">{</span> <span class="number">3.0f</span><span class="special">,</span> <span class="number">4.0f</span><span class="special">,</span> <span class="number">5.0f</span> <span class="special">};</span>
|
||||
|
||||
<span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="special">::</span><span class="identifier">tuple_cat</span><span class="special">(</span> <span class="identifier">t1</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span> <span class="identifier">t2</span> <span class="special">)</span> <span class="special">);</span>
|
||||
<span class="keyword">auto</span> <span class="identifier">result</span> <span class="special">=</span> <span class="special">::</span><span class="identifier">tuple_cat</span><span class="special">(</span> <span class="identifier">t1</span><span class="special">,</span> <span class="identifier">t2</span> <span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Let's fix these one by one. Support for move-only types is easy, if one knows
|
||||
@@ -542,11 +542,11 @@
|
||||
<p>
|
||||
What we need is, given a tuple-like type <code class="computeroutput"><span class="identifier">Tp</span></code>,
|
||||
to obtain <code class="computeroutput"><span class="identifier">mp_list</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_element</span><span class="special"><</span><span class="number">0</span><span class="special">,</span>
|
||||
<span class="identifier">Tp</span><span class="special">>,</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_element</span><span class="special"><</span><span class="number">1</span><span class="special">,</span> <span class="identifier">Tp</span><span class="special">>,</span> <span class="special">...,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_element</span><span class="special"><</span><span class="identifier">N</span><span class="special">-</span><span class="number">1</span><span class="special">,</span> <span class="identifier">Tp</span><span class="special">>></span></code>, where <code class="computeroutput"><span class="identifier">N</span></code>
|
||||
<span class="identifier">Tp</span><span class="special">>::</span><span class="identifier">type</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_element</span><span class="special"><</span><span class="number">1</span><span class="special">,</span>
|
||||
<span class="identifier">Tp</span><span class="special">>::</span><span class="identifier">type</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_element</span><span class="special"><</span><span class="identifier">N</span><span class="special">-</span><span class="number">1</span><span class="special">,</span> <span class="identifier">Tp</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span></code>, where <code class="computeroutput"><span class="identifier">N</span></code>
|
||||
is <code class="computeroutput"><span class="identifier">tuple_size</span><span class="special"><</span><span class="identifier">Tp</span><span class="special">>::</span><span class="identifier">value</span></code>. Here's one way to do it:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">I</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">tuple_element</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_element_t</span><span class="special"><</span><span class="identifier">I</span><span class="special">::</span><span class="identifier">value</span><span class="special">,</span> <span class="identifier">T</span><span class="special">>;</span>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">I</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">tuple_element</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_element</span><span class="special"><</span><span class="identifier">I</span><span class="special">::</span><span class="identifier">value</span><span class="special">,</span> <span class="identifier">T</span><span class="special">>::</span><span class="identifier">type</span><span class="special">;</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">from_tuple_like</span> <span class="special">=</span> <span class="identifier">mp_product</span><span class="special"><</span><span class="identifier">tuple_element</span><span class="special">,</span> <span class="identifier">mp_list</span><span class="special"><</span><span class="identifier">T</span><span class="special">>,</span> <span class="identifier">mp_iota</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_size</span><span class="special"><</span><span class="identifier">T</span><span class="special">>>>;</span>
|
||||
</pre>
|
||||
<p>
|
||||
@@ -591,7 +591,7 @@
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">remove_cv_ref</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">remove_cv</span><span class="special"><</span>
|
||||
<span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">remove_reference</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">type</span><span class="special">>::</span><span class="identifier">type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">I</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">tuple_element</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_element_t</span><span class="special"><</span><span class="identifier">I</span><span class="special">::</span><span class="identifier">value</span><span class="special">,</span> <span class="identifier">T</span><span class="special">>;</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">I</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">tuple_element</span> <span class="special">=</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_element</span><span class="special"><</span><span class="identifier">I</span><span class="special">::</span><span class="identifier">value</span><span class="special">,</span> <span class="identifier">T</span><span class="special">>::</span><span class="identifier">type</span><span class="special">;</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">using</span> <span class="identifier">from_tuple_like</span> <span class="special">=</span> <span class="identifier">mp_product</span><span class="special"><</span><span class="identifier">tuple_element</span><span class="special">,</span> <span class="identifier">mp_list</span><span class="special"><</span><span class="identifier">T</span><span class="special">>,</span> <span class="identifier">mp_iota</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple_size</span><span class="special"><</span><span class="identifier">T</span><span class="special">>>>;</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">Tp</span><span class="special">,</span>
|
||||
@@ -2317,7 +2317,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: May 18, 2017 at 11:57:59 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: May 18, 2017 at 22:41:31 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
||||
Reference in New Issue
Block a user