445,852 Members | 2,219 Online
Need help? Post your question and get tips & solutions from a community of 445,852 IT Pros & Developers. It's quick & easy.

10 Replies

 P: n/a Thanks a lot!!! all. I wrote "AddressPlan = TpAddressPlan[i]"!! That was the issue! Anyway, I didn't knew that "AddressPlan = TpAddressPlan(i)" would work. Thanks a lot! Feb 20 '07 #4

 P: n/a Dave Rahardja wrote: On 20 Feb 2007 05:42:55 -0800, "Erik Wikström" [...]If you are sure that i is in the correct range (0-14) and the valuecorresponds to the right enumeration then just useAddressPlan = TpAddressPlan(i); I've never seen this expression form before. Where is it specified in the standard? 5.2.3 V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask Feb 20 '07 #6

 P: n/a On Tue, 20 Feb 2007 09:39:43 -0500, "Victor Bazarov" wrote: >Dave Rahardja wrote: >On 20 Feb 2007 05:42:55 -0800, "Erik Wikström">[...]If you are sure that i is in the correct range (0-14) and the valuecorresponds to the right enumeration then just useAddressPlan = TpAddressPlan(i); I've never seen this expression form before. Where is it specified inthe standard? 5.2.3 Of course. Somehow I misunderstood what the OP meant. I thought there was a notation whereby you can retrieve the n'th constant in an enumeration, e.g. enum E { FOO = 2, BAR = 4, BAZ = 9 }; E e = E[1]; // e == 4 Which is ill-formed. -dr Feb 22 '07 #7

 P: n/a Dave Rahardja wrote: On Tue, 20 Feb 2007 09:39:43 -0500, "Victor Bazarov" Dave Rahardja wrote: >>On 20 Feb 2007 05:42:55 -0800, "Erik Wikström"

 P: n/a On Thu, 22 Feb 2007 09:27:57 -0500, "Victor Bazarov" wrote: >Of course. Somehow I misunderstood what the OP meant. I thought therewas a notation whereby you can retrieve the n'th constant in anenumeration, e.g.enum E{ FOO = 2, BAR = 4, BAZ = 9};E e = E[1]; // e == 4Which is ill-formed. Well, right, there is no way. That's why there are several "smartenum" implementations out there. Essentially, what's recommended isto implement your own type with conversions to 'int' (if you needthose) and with named constants of that type. If you do, you havethe chance to define your own operator[] which would give you theindexed value. OTOH, using indexing with enumerations does notactually follow the ideology behind enumerations. What you havehere is not an enumeration (named constants) but an array of somevalues which also have tags. You should perhaps consider const int somearray[] = { 2, 4, 9 }; const int& FOO = somearray[0]; const int& BAR = somearray[1]; const int& BAZ = somearray[2];(or even wrapping it into a struct named 'E'...) Yes, but with one difference: an indexed enumeration would be strictly a compile-time construct. You can't take its address, and you can't use a run-time variable as the index. I smell a template metaprogram coming on... -dr Feb 23 '07 #9

 P: n/a Dave Rahardja wrote: On Thu, 22 Feb 2007 09:27:57 -0500, "Victor Bazarov" >Of course. Somehow I misunderstood what the OP meant. I thoughtthere was a notation whereby you can retrieve the n'th constant inan enumeration, e.g.enum E{ FOO = 2, BAR = 4, BAZ = 9};E e = E[1]; // e == 4Which is ill-formed. Well, right, there is no way. That's why there are several "smartenum" implementations out there. Essentially, what's recommended isto implement your own type with conversions to 'int' (if you needthose) and with named constants of that type. If you do, you havethe chance to define your own operator[] which would give you theindexed value. OTOH, using indexing with enumerations does notactually follow the ideology behind enumerations. What you havehere is not an enumeration (named constants) but an array of somevalues which also have tags. You should perhaps consider const int somearray[] = { 2, 4, 9 }; const int& FOO = somearray[0]; const int& BAR = somearray[1]; const int& BAZ = somearray[2];(or even wrapping it into a struct named 'E'...) Yes, but with one difference: an indexed enumeration would be strictly a compile-time construct. You can't take its address, and you can't use a run-time variable as the index. I smell a template metaprogram coming on... It might be an interesting exercise, but I honestly don't see any practical value in it. Do you? V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask Feb 23 '07 #10

 P: n/a On Fri, 23 Feb 2007 08:21:18 -0500, "Victor Bazarov" wrote: >Yes, but with one difference: an indexed enumeration would bestrictly a compile-time construct. You can't take its address, andyou can't use a run-time variable as the index.I smell a template metaprogram coming on... It might be an interesting exercise, but I honestly don't see anypractical value in it. Do you? Sure, as a lookup table at compile time. Come to think of it, it's much easier to use boost::mpl::vector_c

### This discussion thread is closed

Replies have been disabled for this discussion.