I am trying to create a list containing the permutations of a given type list.
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.
Am I using remove incorrectly, or am I running into a different problem?
#include
#include
#include
#include
#include
#include
#include
#include
namespace mpl = boost::mpl;
struct test_type1 {};
struct test_type2 {};
struct test_type3 {};
template< typename T >
struct permutations;
template <typename value>
struct permutations >: mpl::list1 > {};
template< typename value, typename T>
struct permutation_helper:
mpl::transform< typename permutations<
mpl::list1 >::type,
mpl::push_front< mpl::_1, value> > { };
template< typename value, typename T>
struct broken_helper:
mpl::transform< typename permutations<
mpl::remove >::type,
mpl::push_front< mpl::_1, value> > { };
template< typename T >
struct permutations:
mpl::fold< T,
mpl::list0<>,
mpl::joint_view< mpl::_1,
broken_helper > > { };
typedef mpl::list2 typelist;
typedef permutations<typelist>::type perms;
int main() {
BOOST_MPL_ASSERT(( mpl::equal< perms, typelist > ));
return 0;
}
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:
testcase.cpp: In function ‘int main()’:
testcase.cpp:45: error: no matching function for call to
‘assertion_failed(mpl_::failed************
boost::mpl::equal,
boost::mpl::l_end>, boost::mpl::l_end>, boost::mpl::list2, boost::is_same,
mpl_::arg<-0x00000000000000001> > >::************)’
The output using permutation_helper is an actual list:
testcase.cpp: In function ‘int main()’:
testcase.cpp:45: error: no matching function for call to
‘assertion_failed(mpl_::failed************
boost::mpl::equal,
boost::mpl::joint_view,
boost::mpl::l_item,
boost::mpl::l_item, test_type1,
boost::mpl::list1 >, boost::mpl::l_end> >,
boost::mpl::l_item,
boost::mpl::l_item, test_type2,
boost::mpl::list1 >, boost::mpl::l_end> >,
boost::is_same,
mpl_::arg<-0x00000000000000001> > >::************)’