Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>mpl::remove</code> works correctly. The problem is with your template for permutations of singleton lists: it catches only types that are <code>mpl::list</code>s, while the result of remove has another sequence type.</p> <p>With other words, the result of <code>mpl::remove</code> is <code>mpl::equal</code> to the singleton list, but not <code>std::is_same</code>:</p> <pre><code>#include &lt;boost/mpl/list.hpp&gt; #include &lt;boost/mpl/remove.hpp&gt; #include &lt;boost/mpl/equal.hpp&gt; namespace mpl = boost::mpl; struct test_type1 {}; struct test_type2 {}; typedef mpl::list2&lt;test_type1, test_type2&gt; typelist; typedef mpl::remove&lt;typelist, test_type1&gt;::type t; typedef mpl::list1&lt;test_type2&gt; t_corr; static_assert(mpl::equal&lt;t,t_corr&gt;::value, "t equals t_corr"); // the following will fail: // static_assert(std::is_same&lt;t,t_corr&gt;::value, "t same type as t_corr"); int main() { return 0; } </code></pre> <p>You can fix this problem by specializing your template for the singleton list not based on the exact type <code>mpl::list</code>, but on the property to have length 1:</p> <pre><code>#include &lt;boost/mpl/list.hpp&gt; #include &lt;boost/mpl/transform.hpp&gt; #include &lt;boost/mpl/fold.hpp&gt; #include &lt;boost/mpl/push_front.hpp&gt; #include &lt;boost/mpl/joint_view.hpp&gt; #include &lt;boost/mpl/remove.hpp&gt; #include &lt;boost/mpl/assert.hpp&gt; #include &lt;boost/mpl/equal.hpp&gt; #include &lt;boost/mpl/size.hpp&gt; #include &lt;boost/mpl/front.hpp&gt; #include &lt;boost/mpl/begin.hpp&gt; #include &lt;boost/mpl/next.hpp&gt; namespace mpl = boost::mpl; struct test_type1 {}; struct test_type2 {}; struct test_type3 {}; template&lt; typename T, typename _ENABLE=void &gt; struct permutations; template &lt;typename T&gt; struct permutations&lt;T, typename std::enable_if&lt;mpl::size&lt;T&gt;::value==1&gt;::type&gt; { typedef typename mpl::list1&lt;T&gt; type; }; template&lt; typename value, typename T&gt; struct permutation_helper: mpl::transform&lt; typename permutations&lt; mpl::list1&lt;test_type3&gt; &gt;::type, mpl::push_front&lt; mpl::_1, value&gt; &gt; { }; template&lt; typename value, typename T&gt; struct broken_helper: mpl::transform&lt; typename permutations&lt; typename mpl::remove&lt;T, value&gt;::type &gt;::type, mpl::push_front&lt; mpl::_1, value&gt; &gt; { }; template&lt; typename T &gt; struct permutations&lt;T, typename std::enable_if&lt;(mpl::size&lt;T&gt;::value&gt;1)&gt;::type&gt;: mpl::fold&lt; T, mpl::list0&lt;&gt;, mpl::joint_view&lt; mpl::_1, broken_helper&lt;mpl::_2, T &gt; &gt; &gt; { }; typedef mpl::list2&lt;test_type1, test_type2&gt; typelist; typedef permutations&lt;typelist&gt;::type perms; typedef mpl::list&lt;mpl::list&lt;test_type1, test_type2&gt;, mpl::list&lt;test_type2, test_type1&gt; &gt; perms_corr; int main() { static_assert(mpl::size&lt;perms&gt;::value == 2, "perms has correct size"); static_assert(mpl::equal&lt;mpl::front&lt;perms&gt;::type, mpl::front&lt;perms_corr&gt;::type&gt;::value, "perms has correct front"); typedef mpl::next&lt;mpl::begin&lt;perms&gt;::type&gt;::type perms_2nd; typedef mpl::next&lt;mpl::begin&lt;perms_corr&gt;::type&gt;::type perms_corr_2nd; static_assert(mpl::equal&lt;perms_2nd, perms_corr_2nd&gt;::value, "perms has correct 2nd element"); return 0; } </code></pre> <p>By the way, </p> <pre><code>static_assert(mpl::equal&lt;perms, perms_corr&gt;::value, "perms correct"); </code></pre> <p>will fail for exactly the same reasons.</p> <ul> <li>lars</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload