March 28, 2008 Re: Range Type | ||||
|---|---|---|---|---|
| ||||
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
| ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply