www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Extend Enum

reply "Mars" <- -.-> writes:
Hello everybody.
I'd like to know if there's a way, to extend an Enum, based on 
version().
I have an Enum, that holds various values, but some are 
different, in other versions. So the alternative would be to 
define the Enum several times.

 version(x)
 {
 enum example
 {
  FOO = 1,
  BAR = 2,
 }
 }
 else
 {
 enum example
 {
  FOO = 1,
  BAR = 3,
 }
 }
Is there a better way to do this? Maybe a class with static consts...? How should I do it? Mars
Jan 23 2012
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 01/23/2012 02:38 PM, Mars wrote:
 Hello everybody.
 I'd like to know if there's a way, to extend an Enum, based on version().
 I have an Enum, that holds various values, but some are different, in
 other versions. So the alternative would be to define the Enum several
 times.

 version(x)
 {
 enum example
 {
 FOO = 1,
 BAR = 2,
 }
 }
 else
 {
 enum example
 {
 FOO = 1,
 BAR = 3,
 }
 }
Is there a better way to do this? Maybe a class with static consts...? How should I do it? Mars
If it makes sense, you can use version(x) blocks within the single enum definition, as opposed to putting version(x) outside. Alternatively, it may make sense to define the enum value(s) outside to keep the definition of 'example' relatively clean: version(x) { enum BAR_VALUE = 2; } else { enum BAR_VALUE = 3; } enum example { FOO = 1, BAR = BAR_VALUE, } Ali
Jan 23 2012
parent reply "Mars" <- -.-> writes:
On Monday, 23 January 2012 at 22:48:02 UTC, Ali Çehreli wrote:
 If it makes sense, you can use version(x) blocks within the 
 single enum definition, as opposed to putting version(x) 
 outside.
Could you give me an example, what that would look like? So far I couldn't find a way to use version inside an Enum. Mars
Jan 23 2012
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 01/23/2012 04:04 PM, Mars wrote:
 On Monday, 23 January 2012 at 22:48:02 UTC, Ali Çehreli wrote:
 If it makes sense, you can use version(x) blocks within the single
 enum definition, as opposed to putting version(x) outside.
Could you give me an example, what that would look like? So far I couldn't find a way to use version inside an Enum. Mars
Me neither. Sorry for the noise. :( Ali
Jan 23 2012