Specify rhs at initialisation or assignment of typedef' d variable

Cecil Ward via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 31 01:55:49 PDT 2017


On Monday, 31 July 2017 at 08:53:10 UTC, Cecil Ward wrote:
> On Monday, 31 July 2017 at 07:50:57 UTC, inevzxui wrote:
>> [...]
>
> I suspect that I am asking for something that literally makes 
> no sense at all. I wanted to try and avoid opening the door to 
> allowing the following kind of typing error now, eg
>     enum ip_address = 0x11223344;
>     mac_addr_48_t my_mac = cast(mac_addr_48_t) ip_address;
> as if we are going to the bother of introducing strong type 
> checking with Typedef! then the last thing I want to do is 
> encourage is a proliferation of casts.
>
> [...]

Actually, it would be really nice to have some kind of safe 
initialisation helper that checks value ranges, as in this 
particular case I need to make sure that the literal 64-bit value 
fits in 48 bits.


More information about the Digitalmars-d-learn mailing list