1
0
forked from boostorg/mp11

Add mp_insert, mp_erase

This commit is contained in:
Peter Dimov
2017-05-13 21:52:56 +03:00
parent ac28cf9b3f
commit 15e45290d0
6 changed files with 399 additions and 1 deletions

View File

@ -119,6 +119,10 @@
<span class="identifier">I</span><span class="special">&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_take_c_l_n"><code class="computeroutput"><span class="identifier">mp_take_c</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">N</span><span class="special">&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_take_l_n"><code class="computeroutput"><span class="identifier">mp_take</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">N</span><span class="special">&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_insert_c_l_i_t"><code class="computeroutput"><span class="identifier">mp_insert_c</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">,</span> <span class="identifier">T</span><span class="special">...&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_insert_l_i_t"><code class="computeroutput"><span class="identifier">mp_insert</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">,</span> <span class="identifier">T</span><span class="special">...&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_erase_c_l_i_j"><code class="computeroutput"><span class="identifier">mp_erase_c</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">,</span> <span class="identifier">J</span><span class="special">&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_erase_l_i_j"><code class="computeroutput"><span class="identifier">mp_erase</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">,</span> <span class="identifier">J</span><span class="special">&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_replace_l_v_w"><code class="computeroutput"><span class="identifier">mp_replace</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">V</span><span class="special">,</span> <span class="identifier">W</span><span class="special">&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_replace_if_l_p_w"><code class="computeroutput"><span class="identifier">mp_replace_if</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">P</span><span class="special">,</span> <span class="identifier">W</span><span class="special">&gt;</span></code></a></span></dt>
<dt><span class="section"><a href="mp11.html#mp11.reference.algorithm.mp_replace_at_c_l_i_w"><code class="computeroutput"><span class="identifier">mp_replace_at_c</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">,</span> <span class="identifier">W</span><span class="special">&gt;</span></code></a></span></dt>
@ -1238,6 +1242,53 @@
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="mp11.reference.algorithm.mp_insert_c_l_i_t"></a><a class="link" href="mp11.html#mp11.reference.algorithm.mp_insert_c_l_i_t" title="mp_insert_c&lt;L, I, T...&gt;"><code class="computeroutput"><span class="identifier">mp_insert_c</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">,</span> <span class="identifier">T</span><span class="special">...&gt;</span></code></a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">L</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="keyword">class</span><span class="special">...</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">using</span> <span class="identifier">mp_insert_c</span> <span class="special">=</span> <span class="identifier">mp_append</span><span class="special">&lt;</span><span class="identifier">mp_take_c</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">&gt;,</span> <span class="identifier">mp_push_front</span><span class="special">&lt;</span><span class="identifier">mp_drop_c</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">&gt;,</span> <span class="identifier">T</span><span class="special">...&gt;&gt;;</span>
</pre>
<p>
Inserts the elements <code class="computeroutput"><span class="identifier">T</span><span class="special">...</span></code> into the list <code class="computeroutput"><span class="identifier">L</span></code>
at position <code class="computeroutput"><span class="identifier">I</span></code> (a zero-based
index).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="mp11.reference.algorithm.mp_insert_l_i_t"></a><a class="link" href="mp11.html#mp11.reference.algorithm.mp_insert_l_i_t" title="mp_insert&lt;L, I, T...&gt;"><code class="computeroutput"><span class="identifier">mp_insert</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">,</span> <span class="identifier">T</span><span class="special">...&gt;</span></code></a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">L</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">I</span><span class="special">,</span> <span class="keyword">class</span><span class="special">...</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">using</span> <span class="identifier">mp_insert</span> <span class="special">=</span> <span class="identifier">mp_append</span><span class="special">&lt;</span><span class="identifier">mp_take</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">&gt;,</span> <span class="identifier">mp_push_front</span><span class="special">&lt;</span><span class="identifier">mp_drop</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">&gt;,</span> <span class="identifier">T</span><span class="special">...&gt;&gt;;</span>
</pre>
<p>
Same as <code class="computeroutput"><span class="identifier">mp_insert_c</span></code>, but
with a type argument <code class="computeroutput"><span class="identifier">I</span></code>.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="mp11.reference.algorithm.mp_erase_c_l_i_j"></a><a class="link" href="mp11.html#mp11.reference.algorithm.mp_erase_c_l_i_j" title="mp_erase_c&lt;L, I, J&gt;"><code class="computeroutput"><span class="identifier">mp_erase_c</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">,</span> <span class="identifier">J</span><span class="special">&gt;</span></code></a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">L</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">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">J</span><span class="special">&gt;</span> <span class="keyword">using</span> <span class="identifier">mp_erase</span> <span class="special">=</span> <span class="identifier">mp_append</span><span class="special">&lt;</span><span class="identifier">mp_take_c</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">&gt;,</span> <span class="identifier">mp_drop_c</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">J</span><span class="special">&gt;&gt;;</span>
</pre>
<p>
Removes from the list <code class="computeroutput"><span class="identifier">L</span></code>
the elements with indices from <code class="computeroutput"><span class="identifier">I</span></code>
(inclusive) to <code class="computeroutput"><span class="identifier">J</span></code> (exclusive).
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="mp11.reference.algorithm.mp_erase_l_i_j"></a><a class="link" href="mp11.html#mp11.reference.algorithm.mp_erase_l_i_j" title="mp_erase&lt;L, I, J&gt;"><code class="computeroutput"><span class="identifier">mp_erase</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">,</span> <span class="identifier">J</span><span class="special">&gt;</span></code></a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">L</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">I</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">J</span><span class="special">&gt;</span> <span class="keyword">using</span> <span class="identifier">mp_erase</span> <span class="special">=</span> <span class="identifier">mp_append</span><span class="special">&lt;</span><span class="identifier">mp_take</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">I</span><span class="special">&gt;,</span> <span class="identifier">mp_drop</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">J</span><span class="special">&gt;&gt;;</span>
</pre>
<p>
Same as <code class="computeroutput"><span class="identifier">mp_erase_c</span></code>, but
with a type arguments <code class="computeroutput"><span class="identifier">I</span></code>
and <code class="computeroutput"><span class="identifier">J</span></code>.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="mp11.reference.algorithm.mp_replace_l_v_w"></a><a class="link" href="mp11.html#mp11.reference.algorithm.mp_replace_l_v_w" title="mp_replace&lt;L, V, W&gt;"><code class="computeroutput"><span class="identifier">mp_replace</span><span class="special">&lt;</span><span class="identifier">L</span><span class="special">,</span> <span class="identifier">V</span><span class="special">,</span> <span class="identifier">W</span><span class="special">&gt;</span></code></a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">L</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">W</span><span class="special">&gt;</span> <span class="keyword">using</span> <span class="identifier">mp_replace</span> <span class="special">=</span> <span class="comment">/*...*/</span><span class="special">;</span>
@ -1900,7 +1951,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 13, 2017 at 18:11:09 GMT</small></p></td>
<td align="left"><p><small>Last revised: May 13, 2017 at 18:21:04 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>

View File

@ -139,6 +139,30 @@ Same as `mp_at_c`, but with a type argument `I`. `I::value` must be a nonnegativ
Same as `mp_take_c`, but with a type argument `N`. `N::value` must be a nonnegative number.
[endsect]
[section `mp_insert_c<L, I, T...>`]
template<class L, std::size_t I, class... T> using mp_insert_c = mp_append<mp_take_c<L, I>, mp_push_front<mp_drop_c<L, I>, T...>>;
Inserts the elements `T...` into the list `L` at position `I` (a zero-based index).
[endsect]
[section `mp_insert<L, I, T...>`]
template<class L, class I, class... T> using mp_insert = mp_append<mp_take<L, I>, mp_push_front<mp_drop<L, I>, T...>>;
Same as `mp_insert_c`, but with a type argument `I`.
[endsect]
[section `mp_erase_c<L, I, J>`]
template<class L, std::size_t I, std::size_t J> using mp_erase = mp_append<mp_take_c<L, I>, mp_drop_c<L, J>>;
Removes from the list `L` the elements with indices from `I` (inclusive) to `J` (exclusive).
[endsect]
[section `mp_erase<L, I, J>`]
template<class L, class I, class J> using mp_erase = mp_append<mp_take<L, I>, mp_drop<L, J>>;
Same as `mp_erase_c`, but with a type arguments `I` and `J`.
[endsect]
[section `mp_replace<L, V, W>`]
template<class L, class V, class W> using mp_replace = /*...*/;

View File

@ -825,6 +825,7 @@ template<class L, class I, class W> struct mp_replace_at_impl
template<class L, class I, class W> using mp_replace_at = typename detail::mp_replace_at_impl<L, I, W>::type;
template<class L, std::size_t I, class W> using mp_replace_at_c = typename detail::mp_replace_at_impl<L, mp_size_t<I>, W>::type;
//mp_for_each<L>(f)
namespace detail
{
@ -850,6 +851,18 @@ template<class L, class F> BOOST_CONSTEXPR F mp_for_each( F && f )
return detail::mp_for_each_impl( mp_rename<L, mp_list>(), std::forward<F>(f) );
}
// mp_insert<L, I, T...>
template<class L, class I, class... T> using mp_insert = mp_append<mp_take<L, I>, mp_push_front<mp_drop<L, I>, T...>>;
// mp_insert_c<L, I, T...>
template<class L, std::size_t I, class... T> using mp_insert_c = mp_append<mp_take_c<L, I>, mp_push_front<mp_drop_c<L, I>, T...>>;
// mp_erase<L, I, J>
template<class L, class I, class J> using mp_erase = mp_append<mp_take<L, I>, mp_drop<L, J>>;
// mp_erase_c<L, I, J>
template<class L, std::size_t I, std::size_t J> using mp_erase_c = mp_append<mp_take_c<L, I>, mp_drop_c<L, J>>;
} // namespace mp11
} // namespace boost

View File

@ -65,6 +65,8 @@ run mp_none_of.cpp : : : $(REQ) ;
run mp_replace_at.cpp : : : $(REQ) ;
run mp_replace_at_c.cpp : : : $(REQ) ;
run mp_for_each.cpp : : : $(REQ) ;
run mp_insert.cpp : : : $(REQ) ;
run mp_erase.cpp : : : $(REQ) ;
# integral
run integral.cpp : : : $(REQ) ;

171
test/mp_erase.cpp Normal file
View File

@ -0,0 +1,171 @@
// Copyright 2015, 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/mp11/list.hpp>
#include <boost/mp11/integral.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
struct X1 {};
struct X2 {};
struct X3 {};
struct X4 {};
struct X5 {};
int main()
{
using boost::mp11::mp_list;
using boost::mp11::mp_erase;
using boost::mp11::mp_erase_c;
using boost::mp11::mp_size_t;
using _0 = mp_size_t<0>;
using _1 = mp_size_t<1>;
using _2 = mp_size_t<2>;
using _3 = mp_size_t<3>;
using _4 = mp_size_t<4>;
using _5 = mp_size_t<5>;
{
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L1, 0, 0>, L1>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L1, _0, _0>, L1>));
using L2 = mp_list<X1, X2, X3, X4, X5>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 0>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 1, 1>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 2, 2>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 3, 3>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 4, 4>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 5, 5>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _0>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _1, _1>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _2, _2>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _3, _3>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _4, _4>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _5, _5>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 1>, mp_list<X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 1, 2>, mp_list<X1, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 2, 3>, mp_list<X1, X2, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 3, 4>, mp_list<X1, X2, X3, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 4, 5>, mp_list<X1, X2, X3, X4>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _1>, mp_list<X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _1, _2>, mp_list<X1, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _2, _3>, mp_list<X1, X2, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _3, _4>, mp_list<X1, X2, X3, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _4, _5>, mp_list<X1, X2, X3, X4>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 2>, mp_list<X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 1, 3>, mp_list<X1, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 2, 4>, mp_list<X1, X2, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 3, 5>, mp_list<X1, X2, X3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _2>, mp_list<X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _1, _3>, mp_list<X1, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _2, _4>, mp_list<X1, X2, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _3, _5>, mp_list<X1, X2, X3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 3>, mp_list<X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 1, 4>, mp_list<X1, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 2, 5>, mp_list<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _3>, mp_list<X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _1, _4>, mp_list<X1, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _2, _5>, mp_list<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 4>, mp_list<X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 1, 5>, mp_list<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 5>, mp_list<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _4>, mp_list<X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _1, _5>, mp_list<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _5>, mp_list<>>));
using L3 = mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L3, 8, 18>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L3, mp_size_t<8>, mp_size_t<18>>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
}
{
using L1 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L1, 0, 0>, L1>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L1, _0, _0>, L1>));
using L2 = std::tuple<X1, X2, X3, X4, X5>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 0>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 1, 1>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 2, 2>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 3, 3>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 4, 4>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 5, 5>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _0>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _1, _1>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _2, _2>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _3, _3>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _4, _4>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _5, _5>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 1>, std::tuple<X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 1, 2>, std::tuple<X1, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 2, 3>, std::tuple<X1, X2, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 3, 4>, std::tuple<X1, X2, X3, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 4, 5>, std::tuple<X1, X2, X3, X4>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _1>, std::tuple<X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _1, _2>, std::tuple<X1, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _2, _3>, std::tuple<X1, X2, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _3, _4>, std::tuple<X1, X2, X3, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _4, _5>, std::tuple<X1, X2, X3, X4>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 2>, std::tuple<X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 1, 3>, std::tuple<X1, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 2, 4>, std::tuple<X1, X2, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 3, 5>, std::tuple<X1, X2, X3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _2>, std::tuple<X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _1, _3>, std::tuple<X1, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _2, _4>, std::tuple<X1, X2, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _3, _5>, std::tuple<X1, X2, X3>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 3>, std::tuple<X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 1, 4>, std::tuple<X1, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 2, 5>, std::tuple<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _3>, std::tuple<X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _1, _4>, std::tuple<X1, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _2, _5>, std::tuple<X1, X2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 4>, std::tuple<X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 1, 5>, std::tuple<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L2, 0, 5>, std::tuple<>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _4>, std::tuple<X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _1, _5>, std::tuple<X1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L2, _0, _5>, std::tuple<>>));
using L3 = std::tuple<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase_c<L3, 8, 18>, std::tuple<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_erase<L3, mp_size_t<8>, mp_size_t<18>>, std::tuple<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
}
return boost::report_errors();
}

137
test/mp_insert.cpp Normal file
View File

@ -0,0 +1,137 @@
// Copyright 2015, 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/mp11/list.hpp>
#include <boost/mp11/integral.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
struct X1 {};
struct X2 {};
struct X3 {};
struct X4 {};
struct X5 {};
struct Y1 {};
struct Y2 {};
int main()
{
using boost::mp11::mp_list;
using boost::mp11::mp_insert;
using boost::mp11::mp_insert_c;
using boost::mp11::mp_size_t;
{
using L1 = mp_list<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L1, 0>, L1>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L1, mp_size_t<0>>, L1>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L1, 0, Y1>, mp_list<Y1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L1, mp_size_t<0>, Y1>, mp_list<Y1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L1, 0, Y1, Y2>, mp_list<Y1, Y2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L1, mp_size_t<0>, Y1, Y2>, mp_list<Y1, Y2>>));
using L2 = mp_list<X1, X2, X3, X4, X5>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 0>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 1>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 2>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 3>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 4>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 5>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 0, Y1, Y2>, mp_list<Y1, Y2, X1, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 1, Y1, Y2>, mp_list<X1, Y1, Y2, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 2, Y1, Y2>, mp_list<X1, X2, Y1, Y2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 3, Y1, Y2>, mp_list<X1, X2, X3, Y1, Y2, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 4, Y1, Y2>, mp_list<X1, X2, X3, X4, Y1, Y2, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 5, Y1, Y2>, mp_list<X1, X2, X3, X4, X5, Y1, Y2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<0>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<1>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<2>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<3>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<4>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<5>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<0>, Y1, Y2>, mp_list<Y1, Y2, X1, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<1>, Y1, Y2>, mp_list<X1, Y1, Y2, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<2>, Y1, Y2>, mp_list<X1, X2, Y1, Y2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<3>, Y1, Y2>, mp_list<X1, X2, X3, Y1, Y2, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<4>, Y1, Y2>, mp_list<X1, X2, X3, X4, Y1, Y2, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<5>, Y1, Y2>, mp_list<X1, X2, X3, X4, X5, Y1, Y2>>));
using L3 = mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L3, 8>, L3>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L3, mp_size_t<9>>, L3>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L3, 8, Y1, Y2>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, Y1, Y2, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L3, mp_size_t<9>, Y1, Y2>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, Y1, Y2, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
}
{
using L1 = std::tuple<>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L1, 0>, L1>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L1, mp_size_t<0>>, L1>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L1, 0, Y1>, std::tuple<Y1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L1, mp_size_t<0>, Y1>, std::tuple<Y1>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L1, 0, Y1, Y2>, std::tuple<Y1, Y2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L1, mp_size_t<0>, Y1, Y2>, std::tuple<Y1, Y2>>));
using L2 = std::tuple<X1, X2, X3, X4, X5>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 0>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 1>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 2>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 3>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 4>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 5>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 0, Y1, Y2>, std::tuple<Y1, Y2, X1, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 1, Y1, Y2>, std::tuple<X1, Y1, Y2, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 2, Y1, Y2>, std::tuple<X1, X2, Y1, Y2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 3, Y1, Y2>, std::tuple<X1, X2, X3, Y1, Y2, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 4, Y1, Y2>, std::tuple<X1, X2, X3, X4, Y1, Y2, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L2, 5, Y1, Y2>, std::tuple<X1, X2, X3, X4, X5, Y1, Y2>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<0>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<1>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<2>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<3>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<4>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<5>>, L2>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<0>, Y1, Y2>, std::tuple<Y1, Y2, X1, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<1>, Y1, Y2>, std::tuple<X1, Y1, Y2, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<2>, Y1, Y2>, std::tuple<X1, X2, Y1, Y2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<3>, Y1, Y2>, std::tuple<X1, X2, X3, Y1, Y2, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<4>, Y1, Y2>, std::tuple<X1, X2, X3, X4, Y1, Y2, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L2, mp_size_t<5>, Y1, Y2>, std::tuple<X1, X2, X3, X4, X5, Y1, Y2>>));
using L3 = std::tuple<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>;
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L3, 8>, L3>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L3, mp_size_t<9>>, L3>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert_c<L3, 8, Y1, Y2>, std::tuple<X1, X2, X3, X4, X5, X1, X2, X3, Y1, Y2, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_insert<L3, mp_size_t<9>, Y1, Y2>, std::tuple<X1, X2, X3, X4, X5, X1, X2, X3, X4, Y1, Y2, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
}
return boost::report_errors();
}