September 16, 2019 Getting rid of const/immutable | ||||
---|---|---|---|---|
| ||||
I have a particular type name and that type may or may not be const and/or immutable. How do I make a new type based on this that is mutable, ie getting rid of both const and immutable, but not knowing what the original type is ? I don’t want to repeat information from the definition of the original type as this would introduce a bug if the original definition is later changed. Something like alias immutable_cash_t = immutable(float); alias mutable_cash_t = float; // better, in case the original were ever to be changed from ‘float’ to ‘real’ some day alias mutable_cash_t = GetRidOfImmutable!( GetRidOfConst!( mutable_cash_t ) ); |
September 16, 2019 Re: Getting rid of const/immutable | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cecil Ward | On Monday, 16 September 2019 at 05:22:14 UTC, Cecil Ward wrote:
> I have a particular type name and that type may or may not be const and/or immutable. How do I make a new type based on this that is mutable, ie getting rid of both const and immutable, but not knowing what the original type is ?
>
> I don’t want to repeat information from the definition of the original type as this would introduce a bug if the original definition is later changed.
>
>
> Something like
>
> alias immutable_cash_t = immutable(float);
> alias mutable_cash_t = float;
>
> // better, in case the original were ever to be changed from ‘float’ to ‘real’ some day
> alias mutable_cash_t = GetRidOfImmutable!( GetRidOfConst!( mutable_cash_t ) );
If T is you const or immutable type, Unqual!T should be what you want (from std.traits)
but this will also remove shared and I don't know what other modifiers there are.
|
Copyright © 1999-2021 by the D Language Foundation