Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2005-04-26 20:26:42


On 04/26/2005 05:22 PM, Giovanni P. Deretta wrote:
[snip]
>
> As your code demonstrates, enumerators can be used without duplicating
> information, but an enum and map enum->type is required for each tuple.
> This is verbose and should be wrapped in a macro. Then again, I don't

Agreed.

> like macros a lot :)

But mpl and fusion are profuse with macros, or at least
boost/preprocessor.

>
> In the end, getting 'by type' has the same expressive power of using
> enumerators, i simply think that it would have a better syntax and it
> would work out of the box with all tuples without the need of a map.

But it wouldn't work for repeated types, unless, as you
noted previously, some sort of "tag" were "associated" with
the type, which is what an mpl::map does, only it assures there's
only one type associated with each tag; whereas the example:

   tuple<mpl::list<element1_type, element1_tag>, mpl::list<element2_type,
   element2_tag>,.....>

in one of your previous messages:

   http://article.gmane.org/gmane.comp.lib.boost.devel/122595

doesn't assure this, AFAICT. Also, I'd think mpl::pair would be more
succinct. So, the tuple version of the following:

   struct employ
   { string name;
      float salary;
      int ssn;
   };

could be:

   struct name{};
   struct salary{};
   struct ssn{};

   tuple
   < mpl::pair<string,name>
   , mpl::pair<float,salary>
   , mpl::pair<int,ssn>
>::type;

which is not that much shorter than the enum_map_0 shown in my
previous post:

   http://article.gmane.org/gmane.comp.lib.boost.devel/122661

After all, for each enum_map_0::f_i, for i=0..2, there's
got to be a tag with your method:

   struct name{};
   struct salary{};
   struct ssn{};

and there's also got to be a pairing of tags to types, just as in
the enum_map_0::field_map.

Am I missing something?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk