Range Type

bearophile bearophileHUGS at lycos.com
Fri Mar 28 04:08:09 PDT 2008


A range type can be used in many situations:
- You can iterate lazily on a interval, like the foreach in D 2.x, foreach(i; 0..10) {} or foreach(i; 'a'..'z'+1) {} (currently I use xrange() and cinterval() for those things, cinterval is closed on the right).
- You can create a range of values inside an array (currently I use a range() function for this), like arr[] = 0..arr.length.
- You can test if a value is in an interval: (5 in 0..1000) (currently 'in' method of xrange).
- You may be able to define variables that assume only a limited range of integrals/ASCII chars (this is for safety, like in Pascal. The compiler must add run-time controls to be sure you can't go outside the bounds).

Bye,
bearophile



More information about the Digitalmars-d mailing list