From: Larry Evans (cppljevans_at_[hidden])
Date: 2005-04-26 06:58:17
On 04/26/2005 04:18 AM, Giovanni P. Deretta wrote:
> I have been using a small extension to the tuple library 'get' function,
> that I have found very handy. It allows the extraction of an element of
> a tuple by specifying its type instead of the index.
> given the tuple boost::tuple<type1, type2, type3>
> get<type1> returns the first element of the tuple of that type.
> This allows one to write more self describing code: you don't need to
> look up the tuple element type when you find an indexed get function
> buried deep inside some code.
> This is especially useful with nested tuples where for example
> 'get<3>(get<5>(get<0>(my_tuple)))' looks more like line noise than real
> code :).
Of course this wouldn't work for this tuple:
tuple<type1, type1, type3>
Maybe if there were some way of associating an enumeration with the
tuple, you could:
where fi is some enumerator in, e.g.:
but even then, with nested tuples, there's a possible name conflict
amoung the enumerators. Possibly the enumerator names could contain
a prefix indicating to which type they belong:
Obviously more verbose than I think you want, but it would solve the
problem of duplicate types.
BTW, I haven't tried it; hence, there may be some flaws in the idea ;)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk