|
Boost : |
From: Larry Evans (cppljevans_at_[hidden])
Date: 2005-06-27 09:45:19
On 06/27/2005 07:09 AM, Pavel Chikulaev wrote:
> "Roman Yakovenko" <roman.yakovenko_at_[hidden]> wrote in message
> news:BC29F2A417B44F44BD3AA1AD9868CEDC07F9C6_at_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/indexed_types/
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>()
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk