How to create an overwriteable struct that is always const?

drug drug2004 at bk.ru
Sat Jun 1 12:55:24 UTC 2019


01.06.2019 15:51, David Zhang пишет:
> Say I have a struct `S`:
> 
>      struct S {
>          /*const*/ char* pointer;
>          ... other members ...
> 
>          this(/*const*/ char* p, ... others ...) {
>              pointer = p;
>              ...
>          }
>      }
> 
> What I want, is to be able to use `S` in other data structures with the 
> following properties checked by the compiler:
> 
>   - The variable can be set
>   - The variable can be read
>   - The variable cannot be modified, only replaced
> 
> Is there a type-safe way to do this? If this were a class, I'd try 
> std.typecons.Rebindable.
> 
> Thanks

  https://dlang.org/phobos/std_typecons.html#Rebindable ?


More information about the Digitalmars-d-learn mailing list