Ranges - Question about desing choices
Michal Minich via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 24 09:56:25 PDT 2015
On Monday, 24 August 2015 at 15:16:12 UTC, Adam D. Ruppe wrote:
> One advantage of the current design is you can statically
> determine if something is an infinite range by seeing if empty
> is a constant false.
That is important aspect! By having this information at compile
or runtime, you can enforce that algorithms which consume entire
range, and are expected to finish, would not accept this range as
an argument, for example saveToFile(randomNumbersRange).
I see two possible way to model this:
1) provide another property 'bool isInifinite'. This of course
causes dependency on empty property: when isInfinte is false,
empty also needs to be false. This can be complex to enforce.
2) instead of empty property, have state property, returning enum
{ empty, full, infinite }. This might complicate algorithms
implementation, and of course this enum could not be never
extended, since it would be breaking change. For example if
algorithm ask currently for !empty, it would ask for just state
== full, so it might not complicate many algorithms
Any more insights? :)
More information about the Digitalmars-d-learn
mailing list