forked from boostorg/mp11
Add mp_for_index
This commit is contained in:
@@ -148,6 +148,8 @@
|
|||||||
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_none_of_l_p"><code class="computeroutput"><span class="identifier">mp_none_of</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">P</span><span class="special">></span></code></a></span></dt>
|
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_none_of_l_p"><code class="computeroutput"><span class="identifier">mp_none_of</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">P</span><span class="special">></span></code></a></span></dt>
|
||||||
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_any_of_l_p"><code class="computeroutput"><span class="identifier">mp_any_of</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">P</span><span class="special">></span></code></a></span></dt>
|
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_any_of_l_p"><code class="computeroutput"><span class="identifier">mp_any_of</span><span class="special"><</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">P</span><span class="special">></span></code></a></span></dt>
|
||||||
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_for_each_l_f"><code class="computeroutput"><span class="identifier">mp_for_each</span><span class="special"><</span><span class="identifier">L</span><span class="special">>(</span><span class="identifier">f</span><span class="special">)</span></code></a></span></dt>
|
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_for_each_l_f"><code class="computeroutput"><span class="identifier">mp_for_each</span><span class="special"><</span><span class="identifier">L</span><span class="special">>(</span><span class="identifier">f</span><span class="special">)</span></code></a></span></dt>
|
||||||
|
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_for_index_c_n_i_f"><code class="computeroutput"><span class="identifier">mp_for_index_c</span><span class="special"><</span><span class="identifier">N</span><span class="special">>(</span><span class="identifier">i</span><span class="special">,</span> <span class="identifier">f</span><span class="special">)</span></code></a></span></dt>
|
||||||
|
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_for_index_n_i_f"><code class="computeroutput"><span class="identifier">mp_for_index</span><span class="special"><</span><span class="identifier">N</span><span class="special">>(</span><span class="identifier">i</span><span class="special">,</span> <span class="identifier">f</span><span class="special">)</span></code></a></span></dt>
|
||||||
</dl></dd>
|
</dl></dd>
|
||||||
<dt><span class="section"><a href="mp11.html#mp11.reference.set">Set Operations, <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">/</span><span class="identifier">set</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
|
<dt><span class="section"><a href="mp11.html#mp11.reference.set">Set Operations, <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">/</span><span class="identifier">set</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
|
||||||
<dd><dl>
|
<dd><dl>
|
||||||
@@ -200,7 +202,7 @@
|
|||||||
</dl></dd>
|
</dl></dd>
|
||||||
<dt><span class="section"><a href="mp11.html#mp11.reference.tuple_for_each">A "for each"
|
<dt><span class="section"><a href="mp11.html#mp11.reference.tuple_for_each">A "for each"
|
||||||
algorithm for tuple-like types, <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">/</span><span class="identifier">tuple_for_each</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
|
algorithm for tuple-like types, <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">mp11</span><span class="special">/</span><span class="identifier">tuple_for_each</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
|
||||||
<dd><dl><dt><span class="section"><a href="mp11.html#mp11.reference.tuple_for_each.tuple_for_each"><code class="computeroutput"><span class="identifier">tuple_for_each</span></code></a></span></dt></dl></dd>
|
<dd><dl><dt><span class="section"><a href="mp11.html#mp11.reference.tuple_for_each.tuple_for_each_tp_f"><code class="computeroutput"><span class="identifier">tuple_for_each</span><span class="special">(</span><span class="identifier">tp</span><span class="special">,</span> <span class="identifier">f</span><span class="special">)</span></code></a></span></dt></dl></dd>
|
||||||
</dl></dd>
|
</dl></dd>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
@@ -2036,6 +2038,29 @@
|
|||||||
Returns <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special"><</span><span class="identifier">F</span><span class="special">>(</span><span class="identifier">f</span><span class="special">)</span></code>.
|
Returns <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special"><</span><span class="identifier">F</span><span class="special">>(</span><span class="identifier">f</span><span class="special">)</span></code>.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="section">
|
||||||
|
<div class="titlepage"><div><div><h4 class="title">
|
||||||
|
<a name="mp11.reference.algorithm.mp_for_index_c_n_i_f"></a><a class="link" href="mp11.html#mp11.reference.algorithm.mp_for_index_c_n_i_f" title="mp_for_index_c<N>(i, f)"><code class="computeroutput"><span class="identifier">mp_for_index_c</span><span class="special"><</span><span class="identifier">N</span><span class="special">>(</span><span class="identifier">i</span><span class="special">,</span> <span class="identifier">f</span><span class="special">)</span></code></a>
|
||||||
|
</h4></div></div></div>
|
||||||
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="keyword">decltype</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">F</span><span class="special">>()(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">mp_size_t</span><span class="special"><</span><span class="number">0</span><span class="special">>>()))</span> <span class="identifier">mp_for_index</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">F</span> <span class="special">&&</span> <span class="identifier">f</span> <span class="special">);</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
<code class="computeroutput"><span class="identifier">mp_for_index_c</span><span class="special"><</span><span class="identifier">N</span><span class="special">>(</span><span class="identifier">i</span><span class="special">,</span> <span class="identifier">f</span><span class="special">)</span></code> calls <code class="computeroutput"><span class="identifier">f</span></code>
|
||||||
|
with <code class="computeroutput"><span class="identifier">mp_size_t</span><span class="special"><</span><span class="identifier">i</span><span class="special">>()</span></code>
|
||||||
|
and returns the result. <code class="computeroutput"><span class="identifier">i</span></code>
|
||||||
|
must be less than <code class="computeroutput"><span class="identifier">N</span></code>.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="section">
|
||||||
|
<div class="titlepage"><div><div><h4 class="title">
|
||||||
|
<a name="mp11.reference.algorithm.mp_for_index_n_i_f"></a><a class="link" href="mp11.html#mp11.reference.algorithm.mp_for_index_n_i_f" title="mp_for_index<N>(i, f)"><code class="computeroutput"><span class="identifier">mp_for_index</span><span class="special"><</span><span class="identifier">N</span><span class="special">>(</span><span class="identifier">i</span><span class="special">,</span> <span class="identifier">f</span><span class="special">)</span></code></a>
|
||||||
|
</h4></div></div></div>
|
||||||
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="keyword">decltype</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">F</span><span class="special">>()(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">mp_size_t</span><span class="special"><</span><span class="number">0</span><span class="special">>>()))</span> <span class="identifier">mp_for_index</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">F</span> <span class="special">&&</span> <span class="identifier">f</span> <span class="special">);</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
Returns <code class="computeroutput"><span class="identifier">mp_for_index_c</span><span class="special"><</span><span class="identifier">N</span><span class="special">::</span><span class="identifier">value</span><span class="special">>(</span><span class="identifier">i</span><span class="special">,</span> <span class="identifier">f</span><span class="special">)</span></code>.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<div class="titlepage"><div><div><h3 class="title">
|
<div class="titlepage"><div><div><h3 class="title">
|
||||||
@@ -2484,7 +2509,7 @@
|
|||||||
</h3></div></div></div>
|
</h3></div></div></div>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<div class="titlepage"><div><div><h4 class="title">
|
<div class="titlepage"><div><div><h4 class="title">
|
||||||
<a name="mp11.reference.tuple_for_each.tuple_for_each"></a><a class="link" href="mp11.html#mp11.reference.tuple_for_each.tuple_for_each" title="tuple_for_each"><code class="computeroutput"><span class="identifier">tuple_for_each</span></code></a>
|
<a name="mp11.reference.tuple_for_each.tuple_for_each_tp_f"></a><a class="link" href="mp11.html#mp11.reference.tuple_for_each.tuple_for_each_tp_f" title="tuple_for_each(tp, f)"><code class="computeroutput"><span class="identifier">tuple_for_each</span><span class="special">(</span><span class="identifier">tp</span><span class="special">,</span> <span class="identifier">f</span><span class="special">)</span></code></a>
|
||||||
</h4></div></div></div>
|
</h4></div></div></div>
|
||||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Tp</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="keyword">constexpr</span> <span class="identifier">F</span> <span class="identifier">tuple_for_each</span><span class="special">(</span><span class="identifier">Tp</span><span class="special">&&</span> <span class="identifier">tp</span><span class="special">,</span> <span class="identifier">F</span><span class="special">&&</span> <span class="identifier">f</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">Tp</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> <span class="keyword">constexpr</span> <span class="identifier">F</span> <span class="identifier">tuple_for_each</span><span class="special">(</span><span class="identifier">Tp</span><span class="special">&&</span> <span class="identifier">tp</span><span class="special">,</span> <span class="identifier">F</span><span class="special">&&</span> <span class="identifier">f</span><span class="special">);</span>
|
||||||
</pre>
|
</pre>
|
||||||
@@ -2504,7 +2529,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||||
<td align="left"><p><small>Last revised: May 28, 2017 at 23:51:44 GMT</small></p></td>
|
<td align="left"><p><small>Last revised: May 31, 2017 at 16:52:56 GMT</small></p></td>
|
||||||
<td align="right"><div class="copyright-footer"></div></td>
|
<td align="right"><div class="copyright-footer"></div></td>
|
||||||
</tr></table>
|
</tr></table>
|
||||||
<hr>
|
<hr>
|
||||||
|
@@ -289,4 +289,16 @@ is `mp_size<L>`.
|
|||||||
Returns `std::forward<F>(f)`.
|
Returns `std::forward<F>(f)`.
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
[section `mp_for_index_c<N>(i, f)`]
|
||||||
|
template<std::size_t N, class F> decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) mp_for_index( std::size_t i, F && f );
|
||||||
|
|
||||||
|
`mp_for_index_c<N>(i, f)` calls `f` with `mp_size_t<i>()` and returns the result. `i` must be less than `N`.
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[section `mp_for_index<N>(i, f)`]
|
||||||
|
template<class N, class F> decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) mp_for_index( std::size_t i, F && f );
|
||||||
|
|
||||||
|
Returns `mp_for_index_c<N::value>(i, f)`.
|
||||||
|
[endsect]
|
||||||
|
|
||||||
[endsect:algorithm]
|
[endsect:algorithm]
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
[section:tuple_for_each A "for each" algorithm for tuple-like types, `<boost/mp11/tuple_for_each.hpp>`]
|
[section:tuple_for_each A "for each" algorithm for tuple-like types, `<boost/mp11/tuple_for_each.hpp>`]
|
||||||
|
|
||||||
[section `tuple_for_each`]
|
[section `tuple_for_each(tp, f)`]
|
||||||
template<class Tp, class F> constexpr F tuple_for_each(Tp&& tp, F&& f);
|
template<class Tp, class F> constexpr F tuple_for_each(Tp&& tp, F&& f);
|
||||||
|
|
||||||
`tuple_for_each(tp, f)` applies the function object `f` to each element of `tp` by evaluating the
|
`tuple_for_each(tp, f)` applies the function object `f` to each element of `tp` by evaluating the
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
#include <boost/mp11/detail/mp_count.hpp>
|
#include <boost/mp11/detail/mp_count.hpp>
|
||||||
#include <boost/mp11/detail/mp_plus.hpp>
|
#include <boost/mp11/detail/mp_plus.hpp>
|
||||||
#include <boost/mp11/detail/mp_map_find.hpp>
|
#include <boost/mp11/detail/mp_map_find.hpp>
|
||||||
|
#include <boost/mp11/detail/mp_for_index.hpp>
|
||||||
#include <boost/mp11/detail/config.hpp>
|
#include <boost/mp11/detail/config.hpp>
|
||||||
#include <boost/mp11/integer_sequence.hpp>
|
#include <boost/mp11/integer_sequence.hpp>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
365
include/boost/mp11/detail/mp_for_index.hpp
Normal file
365
include/boost/mp11/detail/mp_for_index.hpp
Normal file
@@ -0,0 +1,365 @@
|
|||||||
|
#ifndef BOOST_MP11_DETAIL_MP_FOR_INDEX_HPP_INCLUDED
|
||||||
|
#define BOOST_MP11_DETAIL_MP_FOR_INDEX_HPP_INCLUDED
|
||||||
|
|
||||||
|
// Copyright 2017 Peter Dimov.
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
//
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/mp11/integral.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
namespace mp11
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template<std::size_t N> struct mp_for_index_impl_
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
case 7: return std::forward<F>(f)( mp_size_t<K+7>() );
|
||||||
|
case 8: return std::forward<F>(f)( mp_size_t<K+8>() );
|
||||||
|
case 9: return std::forward<F>(f)( mp_size_t<K+9>() );
|
||||||
|
case 10: return std::forward<F>(f)( mp_size_t<K+10>() );
|
||||||
|
case 11: return std::forward<F>(f)( mp_size_t<K+11>() );
|
||||||
|
case 12: return std::forward<F>(f)( mp_size_t<K+12>() );
|
||||||
|
case 13: return std::forward<F>(f)( mp_size_t<K+13>() );
|
||||||
|
case 14: return std::forward<F>(f)( mp_size_t<K+14>() );
|
||||||
|
case 15: return std::forward<F>(f)( mp_size_t<K+15>() );
|
||||||
|
}
|
||||||
|
|
||||||
|
return mp_for_index_impl_<N-16>::template call<K+16>( i-16, std::forward<F>(f) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<0>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<1>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<2>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<3>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<4>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<5>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<6>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<7>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<8>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
case 7: return std::forward<F>(f)( mp_size_t<K+7>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<9>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
case 7: return std::forward<F>(f)( mp_size_t<K+7>() );
|
||||||
|
case 8: return std::forward<F>(f)( mp_size_t<K+8>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<10>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
case 7: return std::forward<F>(f)( mp_size_t<K+7>() );
|
||||||
|
case 8: return std::forward<F>(f)( mp_size_t<K+8>() );
|
||||||
|
case 9: return std::forward<F>(f)( mp_size_t<K+9>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<11>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
case 7: return std::forward<F>(f)( mp_size_t<K+7>() );
|
||||||
|
case 8: return std::forward<F>(f)( mp_size_t<K+8>() );
|
||||||
|
case 9: return std::forward<F>(f)( mp_size_t<K+9>() );
|
||||||
|
case 10: return std::forward<F>(f)( mp_size_t<K+10>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<12>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
case 7: return std::forward<F>(f)( mp_size_t<K+7>() );
|
||||||
|
case 8: return std::forward<F>(f)( mp_size_t<K+8>() );
|
||||||
|
case 9: return std::forward<F>(f)( mp_size_t<K+9>() );
|
||||||
|
case 10: return std::forward<F>(f)( mp_size_t<K+10>() );
|
||||||
|
case 11: return std::forward<F>(f)( mp_size_t<K+11>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<13>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
case 7: return std::forward<F>(f)( mp_size_t<K+7>() );
|
||||||
|
case 8: return std::forward<F>(f)( mp_size_t<K+8>() );
|
||||||
|
case 9: return std::forward<F>(f)( mp_size_t<K+9>() );
|
||||||
|
case 10: return std::forward<F>(f)( mp_size_t<K+10>() );
|
||||||
|
case 11: return std::forward<F>(f)( mp_size_t<K+11>() );
|
||||||
|
case 12: return std::forward<F>(f)( mp_size_t<K+12>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<14>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
case 7: return std::forward<F>(f)( mp_size_t<K+7>() );
|
||||||
|
case 8: return std::forward<F>(f)( mp_size_t<K+8>() );
|
||||||
|
case 9: return std::forward<F>(f)( mp_size_t<K+9>() );
|
||||||
|
case 10: return std::forward<F>(f)( mp_size_t<K+10>() );
|
||||||
|
case 11: return std::forward<F>(f)( mp_size_t<K+11>() );
|
||||||
|
case 12: return std::forward<F>(f)( mp_size_t<K+12>() );
|
||||||
|
case 13: return std::forward<F>(f)( mp_size_t<K+13>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<15>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
case 7: return std::forward<F>(f)( mp_size_t<K+7>() );
|
||||||
|
case 8: return std::forward<F>(f)( mp_size_t<K+8>() );
|
||||||
|
case 9: return std::forward<F>(f)( mp_size_t<K+9>() );
|
||||||
|
case 10: return std::forward<F>(f)( mp_size_t<K+10>() );
|
||||||
|
case 11: return std::forward<F>(f)( mp_size_t<K+11>() );
|
||||||
|
case 12: return std::forward<F>(f)( mp_size_t<K+12>() );
|
||||||
|
case 13: return std::forward<F>(f)( mp_size_t<K+13>() );
|
||||||
|
case 14: return std::forward<F>(f)( mp_size_t<K+14>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct mp_for_index_impl_<16>
|
||||||
|
{
|
||||||
|
template<std::size_t K, class F> static decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) call( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
switch( i )
|
||||||
|
{
|
||||||
|
case 0: return std::forward<F>(f)( mp_size_t<K+0>() );
|
||||||
|
case 1: return std::forward<F>(f)( mp_size_t<K+1>() );
|
||||||
|
case 2: return std::forward<F>(f)( mp_size_t<K+2>() );
|
||||||
|
case 3: return std::forward<F>(f)( mp_size_t<K+3>() );
|
||||||
|
case 4: return std::forward<F>(f)( mp_size_t<K+4>() );
|
||||||
|
case 5: return std::forward<F>(f)( mp_size_t<K+5>() );
|
||||||
|
case 6: return std::forward<F>(f)( mp_size_t<K+6>() );
|
||||||
|
case 7: return std::forward<F>(f)( mp_size_t<K+7>() );
|
||||||
|
case 8: return std::forward<F>(f)( mp_size_t<K+8>() );
|
||||||
|
case 9: return std::forward<F>(f)( mp_size_t<K+9>() );
|
||||||
|
case 10: return std::forward<F>(f)( mp_size_t<K+10>() );
|
||||||
|
case 11: return std::forward<F>(f)( mp_size_t<K+11>() );
|
||||||
|
case 12: return std::forward<F>(f)( mp_size_t<K+12>() );
|
||||||
|
case 13: return std::forward<F>(f)( mp_size_t<K+13>() );
|
||||||
|
case 14: return std::forward<F>(f)( mp_size_t<K+14>() );
|
||||||
|
case 15: return std::forward<F>(f)( mp_size_t<K+15>() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
template<std::size_t N, class F> inline decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) mp_for_index_c( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
assert( i < N );
|
||||||
|
return detail::mp_for_index_impl_<N>::template call<0>( i, std::forward<F>(f) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class N, class F> inline decltype(std::declval<F>()(std::declval<mp_size_t<0>>())) mp_for_index( std::size_t i, F && f )
|
||||||
|
{
|
||||||
|
return mp_for_index_c<N::value>( i, std::forward<F>(f) );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mp11
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // #ifndef BOOST_MP11_DETAIL_MP_FIND_INDEX_HPP_INCLUDED
|
@@ -71,6 +71,7 @@ run mp_replace_at_c.cpp : : : $(REQ) ;
|
|||||||
run mp_for_each.cpp : : : $(REQ) ;
|
run mp_for_each.cpp : : : $(REQ) ;
|
||||||
run mp_insert.cpp : : : $(REQ) ;
|
run mp_insert.cpp : : : $(REQ) ;
|
||||||
run mp_erase.cpp : : : $(REQ) ;
|
run mp_erase.cpp : : : $(REQ) ;
|
||||||
|
run mp_for_index.cpp : : : $(REQ) ;
|
||||||
|
|
||||||
# integral
|
# integral
|
||||||
run integral.cpp : : : $(REQ) ;
|
run integral.cpp : : : $(REQ) ;
|
||||||
|
90
test/mp_for_index.cpp
Normal file
90
test/mp_for_index.cpp
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
|
||||||
|
// Copyright 2017 Peter Dimov.
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
//
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/mp11/algorithm.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/detail/workaround.hpp>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
using boost::mp11::mp_size_t;
|
||||||
|
using boost::mp11::mp_for_each;
|
||||||
|
using boost::mp11::mp_for_index;
|
||||||
|
using boost::mp11::mp_for_index_c;
|
||||||
|
using boost::mp11::mp_iota_c;
|
||||||
|
|
||||||
|
struct F
|
||||||
|
{
|
||||||
|
int i_;
|
||||||
|
|
||||||
|
explicit F( int i ): i_( i ) {}
|
||||||
|
|
||||||
|
template<std::size_t I> void operator()( mp_size_t<I> ) const
|
||||||
|
{
|
||||||
|
BOOST_TEST_EQ( I, i_ );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct G
|
||||||
|
{
|
||||||
|
void operator()( mp_size_t<0> ) const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t N> void operator()( mp_size_t<N> ) const
|
||||||
|
{
|
||||||
|
for( std::size_t i = 0; i < N; ++i )
|
||||||
|
{
|
||||||
|
mp_for_index_c<N>( i, F(i) );
|
||||||
|
mp_for_index<mp_size_t<N>>( i, F(i) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
#if BOOST_WORKAROUND( BOOST_MSVC, < 1900 )
|
||||||
|
|
||||||
|
G()( mp_size_t<1>{} );
|
||||||
|
G()( mp_size_t<2>{} );
|
||||||
|
G()( mp_size_t<3>{} );
|
||||||
|
G()( mp_size_t<4>{} );
|
||||||
|
G()( mp_size_t<5>{} );
|
||||||
|
G()( mp_size_t<6>{} );
|
||||||
|
G()( mp_size_t<7>{} );
|
||||||
|
G()( mp_size_t<8>{} );
|
||||||
|
G()( mp_size_t<9>{} );
|
||||||
|
G()( mp_size_t<10>{} );
|
||||||
|
G()( mp_size_t<11>{} );
|
||||||
|
G()( mp_size_t<12>{} );
|
||||||
|
G()( mp_size_t<13>{} );
|
||||||
|
G()( mp_size_t<14>{} );
|
||||||
|
G()( mp_size_t<15>{} );
|
||||||
|
G()( mp_size_t<16>{} );
|
||||||
|
|
||||||
|
G()( mp_size_t<32+1>{} );
|
||||||
|
|
||||||
|
G()( mp_size_t<48+2>{} );
|
||||||
|
|
||||||
|
G()( mp_size_t<64+3>{} );
|
||||||
|
|
||||||
|
G()( mp_size_t<96+4>{} );
|
||||||
|
|
||||||
|
G()( mp_size_t<112+5>{} );
|
||||||
|
|
||||||
|
G()( mp_size_t<128+6>{} );
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
mp_for_each<mp_iota_c<134>>( G() );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user