Getting rid of const/immutable

Dominikus Dittes Scherkl dominikus.scherkl at continental-corporation.com
Mon Sep 16 05:44:03 UTC 2019


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.


More information about the Digitalmars-d-learn mailing list