Re: [boost] Is there any interest in tagged tuple?

From: Pavel Chikulaev [mailto:pavel.chikulaev@gmail.com]
Hi all,
Is there any interest in tagged tuple as extension of tuples library or fusion library? The example:
struct name_t {}; //tagged types struct year_t {};
void foo() { tagged_tuple<std::string, name_t, int, year_t> s;
s.get<name_t>() = "Hello World"!; s.get<year_t>() = 2005; assert(s.get<0>() == s.get<name_t>()); assert(s.get<1>() == s.get<year_t>()); }
It already works in VC7.1 and VC8.0 :)
What do you think?
If you try to solve code readability then adding simple enum, even unnamed, solves the problem enum { name, year }; s.get<name>() If you try to solve an other problem, please describe the problem first. And second this has been already discussed on the list. One of the objections was the use case where you have same type occurs more then once in tuple. tagged_tuple<std::string, name_t, std::string, name_t > s; s.get<name_t>() - is this operation defined and what it's result
Pavel Chikulaev
Roman

"Roman Yakovenko" <roman.yakovenko@actimize.com> wrote in message news:BC29F2A417B44F44BD3AA1AD9868CEDC07F9C6@ilexchange.adrembi.com...
If you try to solve code readability then adding simple enum, even unnamed, solves the problem
enum { name, year }; s.get<name>() I don't like this, because of the following: tuple<double, double> s; enum { width, height }; tuple<double, double> p; enum { apples_weight, bananas_weight }; s.get<width>() = 1.04; double apples_price = s.get<apples_weight>()* 5; (mistake: there should be p instead of s)
If you try to solve an other problem, please describe the problem first. Yeah, sorry, I forgot to mention that explicitly. No just this one.
And second this has been already discussed on the list. Sorry again :) One of the objections was the use case where you have same type occurs more then once in tuple.
tagged_tuple<std::string, name_t, std::string, name_t > s;
s.get<name_t>() - is this operation defined and what it's result With current implemention, such object can not be created...
My rationale for it: tag is like a name, but it to be applied in compile time, and as in case of objects there cannot be two objects(two tuple elements) with the same name. -- Pavel Chikulaev

On 06/27/2005 07:09 AM, Pavel Chikulaev wrote:
"Roman Yakovenko" <roman.yakovenko@actimize.com> wrote in message news:BC29F2A417B44F44BD3AA1AD9868CEDC07F9C6@ilexchange.adrembi.com...
If you try to solve code readability then adding simple enum, even unnamed, solves the problem
enum { name, year }; s.get<name>()
I don't like this, because of the following: tuple<double, double> s; enum { width, height }; tuple<double, double> p; enum { apples_weight, bananas_weight }; s.get<width>() = 1.04; double apples_price = s.get<apples_weight>()* 5; (mistake: there should be p instead of s) Would something from indexed_types:
http://cvs.sourceforge.net/viewcvs.py/boost-sandbox/boost-sandbox/boost/inde... satisfy you needs? It would have the problem mentioned above because the "index" (i.e. the enumerator) is specific to the tuple. IOW s.get<apples_weight>() would result in a compile time error because s.get<...> requires something from: enum width_height{width,height}; Of course, instead of get, the template member function, in the case of composite_product.hpp, is project<...>; so, it would actually be: s.project<width>()
participants (3)
-
Larry Evans
-
Pavel Chikulaev
-
Roman Yakovenko