Note that there are some explanatory texts on larger screens.

plurals
  1. POPermutations of a List of Types Using boost::mpl
    text
    copied!<p>I am trying to create a list containing the permutations of a given type list. </p> <p>The below code seems to function, though without the intended result, when I use a specified list instead of generating a new list by removing from the actual input. This is demonstrated by the difference between permutation_helper and broken_helper below.</p> <p>Does anyone know why <code>mpl::remove</code> doesn't seem to function as expected in this circumstance?</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; namespace mpl = boost::mpl; struct test_type1 {}; struct test_type2 {}; struct test_type3 {}; template&lt; typename T &gt; struct permutations; template &lt;typename value&gt; struct permutations&lt;mpl::list1&lt; value &gt; &gt;: mpl::list1&lt;mpl::list1&lt; value &gt; &gt; {}; 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; mpl::remove&lt;T, value&gt; &gt;::type, mpl::push_front&lt; mpl::_1, value&gt; &gt; { }; template&lt; typename T &gt; struct permutations: 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; int main() { BOOST_MPL_ASSERT(( mpl::equal&lt; perms, typelist &gt; )); return 0; } </code></pre> <p>I used the assert to determine what is being returned from the function, typelist is not the expected result. This is the message the assert returns for broken_helper:</p> <pre><code>testcase.cpp: In function ‘int main()’: testcase.cpp:45: error: no matching function for call to ‘assertion_failed(mpl_::failed************ boost::mpl::equal&lt;boost::mpl::joint_view&lt;boost::mpl::joint_view&lt;boost::mpl::list0&lt;mpl_::na&gt;, boost::mpl::l_end&gt;, boost::mpl::l_end&gt;, boost::mpl::list2&lt;test_type1, test_type2&gt;, boost::is_same&lt;mpl_::arg&lt;-0x00000000000000001&gt;, mpl_::arg&lt;-0x00000000000000001&gt; &gt; &gt;::************)’ </code></pre> <p>The output using permutation_helper is an actual list:</p> <pre><code>testcase.cpp: In function ‘int main()’: testcase.cpp:45: error: no matching function for call to ‘assertion_failed(mpl_::failed************ boost::mpl::equal&lt;boost::mpl::list2&lt;test_type1, test_type2&gt;, boost::mpl::joint_view&lt;boost::mpl::joint_view&lt;boost::mpl::list0&lt;mpl_::na&gt;, boost::mpl::l_item&lt;mpl_::long_&lt;1l&gt;, boost::mpl::l_item&lt;mpl_::long_&lt;2l&gt;, test_type1, boost::mpl::list1&lt;test_type3&gt; &gt;, boost::mpl::l_end&gt; &gt;, boost::mpl::l_item&lt;mpl_::long_&lt;1l&gt;, boost::mpl::l_item&lt;mpl_::long_&lt;2l&gt;, test_type2, boost::mpl::list1&lt;test_type3&gt; &gt;, boost::mpl::l_end&gt; &gt;, boost::is_same&lt;mpl_::arg&lt;-0x00000000000000001&gt;, mpl_::arg&lt;-0x00000000000000001&gt; &gt; &gt;::************)’ </code></pre>
 

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