Re: Creating a "fixed-range int" with opDispatch and/or alias this?

2016-06-02 Thread tsbockman via Digitalmars-d-learn
On Wednesday, 1 June 2016 at 19:59:51 UTC, Mark Isaacson wrote: I'm trying to create a type that for all intents and purposes behaves exactly like an int except that it limits its values to be within a certain range [a,b]. Theoretically, I would think this looks something like: ... It looks

Re: Creating a "fixed-range int" with opDispatch and/or alias this?

2016-06-02 Thread Ali Çehreli via Digitalmars-d-learn
On 06/02/2016 07:59 AM, Ali Çehreli wrote: > On 06/01/2016 12:59 PM, Mark Isaacson wrote: >> I'm trying to create a type that for all intents and purposes behaves >> exactly like an int except that it limits its values to be within a >> certain range [a,b]. > > 'alias this' with property

Re: Creating a "fixed-range int" with opDispatch and/or alias this?

2016-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 06/02/2016 04:59 PM, Ali Çehreli wrote: 'alias this' with property functions work at least for your example: struct FixedRangeInt { int min; int max; int i_; int value() const { return i_; } void value(int i) { assert(i >= min);

Re: Creating a "fixed-range int" with opDispatch and/or alias this?

2016-06-02 Thread Ali Çehreli via Digitalmars-d-learn
On 06/01/2016 12:59 PM, Mark Isaacson wrote: I'm trying to create a type that for all intents and purposes behaves exactly like an int except that it limits its values to be within a certain range [a,b]. 'alias this' with property functions work at least for your example: struct

Re: Creating a "fixed-range int" with opDispatch and/or alias this?

2016-06-01 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 1 June 2016 at 19:59:51 UTC, Mark Isaacson wrote: FWIW, the fixed range int part of this question is just an example, I'm mostly just interested in whether this idea is possible without a lot of bloat/duplication. I suspect not.. Here's how std.typecons.Proxy is doing it:

Creating a "fixed-range int" with opDispatch and/or alias this?

2016-06-01 Thread Mark Isaacson via Digitalmars-d-learn
I'm trying to create a type that for all intents and purposes behaves exactly like an int except that it limits its values to be within a certain range [a,b]. Theoretically, I would think this looks something like: struct FixedRangeInt { this(int min, int max, int value=0) { this.min =