Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 23, 2012 Extend Enum | ||||
---|---|---|---|---|
| ||||
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
|
January 23, 2012 Re: Extend Enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mars | 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
|
January 24, 2012 Re: Extend Enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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
|
January 24, 2012 Re: Extend Enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mars | 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
|
Copyright © 1999-2021 by the D Language Foundation