----- Original Message -----
From: "Larry Evans"
To:
Sent: Monday, February 01, 2010 1:03 AM
Subject: Re: [Boost-users] generate structs with all combinations of members from a given struct
Hello,
Larry thanks for all the answers.
I have a little trouble following your trail of thoughts, especially step 2, but let me reread your posts a couple of times more to get it right.
I think your solution is rather build more solutions than required then remove those which are not a "combination" in the mathematical sense. It may cause problems when my structs have more than 15 members in which case we may be working with 15! to get back to 2^15 -1
again, let me reread your posts first.
In the meantime, I have written the pure runtime version of the problem which is in fact like a tree recursive descent problem.(I think), this builds and runs correctly but doesn't deal with the identical types and member names.
#include <iostream>
#include <list>
typedef std::list< std::list > main_list_t;
void combinations(main_list_t& m, const size_t* arr, size_t arrsize)
{
if (arrsize==0)
return;
if (m.empty()) {
std::list l;
l.push_back( arr[0] );
m.push_back(l);
}
else {
std::list l( m.back() );
l.push_back( arr[0] );
m.push_back( l );
}
combinations(m, arr+1, arrsize-1);
}
int main()
{
const size_t arr[] = { 1, 2, 3, 4, 5 };
const size_t arrsize = sizeof(arr)/sizeof(size_t);
main_list_t m[arrsize];
for (size_t s=0; s& l = *i;
for (std::list::const_iterator ii = l.begin(); ii!=l.end(); ++ii) {
std::cout<< *ii << '\t';
}
std::cout<