Boost logo

Boost :

From: Giovanni P. Deretta (lordshoo_at_[hidden])
Date: 2005-04-26 17:22:05


Larry Evans wrote:
>
> But isn't an enumerator in some enumeration the equivalent of
> an "element tag"?
>

Yes,

>
> The enumerator can also be thought of as a name.
>

yes,

>
> Which can be done with enumerators also.
>

and also yes.

>
> But again, I don't see why adding a tag is any better than using an
> enumerator. The only difference between an array (all elements of
> the same type) and a tuple, is that the type of the value as well
> as the value depends on the index. And if the types are indexed
> by the same enumeration, then you've solve the problem. In addition,
> a similar scheme can be used for variants (or disjoint sum). See
>
> http://cvs.sourceforge.net/viewcvs.py/boost-sandbox/boost-sandbox/libs/indexed_types/test/sum.cpp?view=markup
>

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
like macros a lot :)

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.

>
>>
>> BTW, tuples containing many objects of the same type are better seen
>> as containers, thus the indexed get is fine.
>
>
> Agreed, but the indexed get works just as well when the argument is
> an enumerator instead of a literal unsigned, and when it's an
> enumerator, the meaning is clearer:
>
> t.get<0>();
> t.get<1>();
>
> is obviously not as clear as:
>
> t.get<first_field>();
> t.get<second_field>();
>
> [snip]

Well, i actually believe the first to be clearer. It is a matter of
taste though.

--
Giovanni P. Deretta

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