Boost logo

Boost Users :

Subject: Re: [Boost-users] generate structs with all combinations of members from a given struct
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-02-10 11:14:40


> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of Larry Evans
> Sent: 10 February 2010 13:10
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] generate structs with all combinations of
members
> from a given struct
>
> On 02/09/10 16:12, Hicham Mouline wrote:
> [snip]
> > I have another problem for now.
>
> What about precompiled headers? Microsoft provides them:
>
> http://msdn.microsoft.com/en-us/library/szfdksca(VS.71).aspx
>
> as well as gcc:
>
> http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
>
> HTH.
>
> -Larry

Ah yes, I will look into that, gcc and msvc are the only 2 compilers I use
anyways, thanks,

Daniel, in the attached file in
http://lists.boost.org/boost-users/2010/02/56100.php, in line 69, I am
generating the struct name with a BOOST_PP_WHILE invocation, I then need to
reuse the struct name to define a constructor for the struct, so I reinvoke
the BOOST_PP_WHILE.
Clearly, this is wasted reprocessing, but I don't see how to avoid it.
Actually, it's not the struct constructor I need to write, but the
assignment operator instead.
The 2nd question is how to generate the struct definition including the
operator= on multiple lines instead of just 1.

Here is an example of the generation at work

struct S {
  double d1;
  int i2;
  long l3;
};

1 of the 7 structs generated will look like

struct S_i2_l3 {
  S_i2_l3& operator=( const S& rhs )
  {
    i2 = rhs.i2;
    l3 = rhs.l3;
  }
  int i2;
  long l3;
};

All the S_s should be generated just once ( I will look at precompiled
headers for this )

Later on, I PP-generate these types

typedef boost::multi_array<S_i2_l3, 5> multi_array_i2_l3; //// The 5 may be
different for each of the 100 translation units

because this multiarray may be very large (possibly millions of cells) it is
useful to optimize the memory footprint.

Had I indiscriminately used boost::multi_array<S,5>, and just filled/read
from the S cells just the relevant fields, I would be wasting memory.

Thanks,


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net