
On 02/01/10 03:08, Hicham Mouline wrote:
----- Original Message ----- *From:* Hicham Mouline mailto:hicham@mouline.org *To:* boost-users@lists.boost.org mailto:boost-users@lists.boost.org *Sent:* Monday, February 01, 2010 12:09 PM *Subject:* Re: [Boost-users] generate structs with all combinations of members from a given struct
My previous runtime solution was wrong. I just fixed it now.
I had a hard time understanding how it worked. A simpler solution would be to just generate the characteristic functions for sets of a given size. The characteristic function could then be used to select elements from the set: http://en.wikipedia.org/wiki/Characteristic_function The structure of such a program is very similar to yours in that it has a recursive call and a for loop. However, with this method, the for loop just has size 2. The depth of recursion is n, where n is size of the set. I think your method had recursion depth of n-1. The attached illustrates the method. Output is: size=32 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 0 0 1 1 0 1 0 1 1 0 0 1 1 1 0 1 1 1 1 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 1 0 1 0 1 0 1 1 0 1 1 1 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 0 1 1 1 1 0 1 1 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 -regards, Larry