Re: Range checked assignment

2020-09-09 Thread Cecil Ward via Digitalmars-d-learn
On Tuesday, 8 September 2020 at 16:04:29 UTC, Harry Gillanders wrote: On Tuesday, 8 September 2020 at 14:18:14 UTC, Cecil Ward wrote: [...] If you want to define an integral-like type which is more-or-less interchangeable with the native integral types, you'll need to provide the following

Re: Range checked assignment

2020-09-08 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 8 September 2020 at 14:18:14 UTC, Cecil Ward wrote: I assumed I would have to create a struct type definition and handle various operators. How many will I have to handle? I would of course make it a template so I can reuse this otherwise horribly repetitive code. You can see a fu

Re: Range checked assignment

2020-09-08 Thread Harry Gillanders via Digitalmars-d-learn
On Tuesday, 8 September 2020 at 14:18:14 UTC, Cecil Ward wrote: What I would like to do is (in pseudo-code) : declare_var my_var : int range 0..7; // i.e. 0 <= val <= 7; my_var = 6; // ok my_var = 8; // bang ! static assert fail or assert fail at runtime my_var = 6; my_var

Re: Range checked assignment

2020-09-08 Thread Mitacha via Digitalmars-d-learn
On Tuesday, 8 September 2020 at 14:18:14 UTC, Cecil Ward wrote: What I would like to do is (in pseudo-code) : declare_var my_var : int range 0..7; // i.e. 0 <= val <= 7; my_var = 6; // ok my_var = 8; // bang ! static assert fail or assert fail at runtime my_var = 6; my_var

Range checked assignment

2020-09-08 Thread Cecil Ward via Digitalmars-d-learn
What I would like to do is (in pseudo-code) : declare_var my_var : int range 0..7; // i.e. 0 <= val <= 7; my_var = 6; // ok my_var = 8; // bang ! static assert fail or assert fail at runtime my_var = 6; my_var += 2; // bang ! value 8 is > 7 So every assignment is range-che