On Tuesday, 29 April 2014 at 08:21:04 UTC, John Colvin wrote:
On Monday, 28 April 2014 at 23:02:03 UTC, bearophile wrote:
I think it could be a good idea to add something intermediate to D: optional strong typing for array indexing. I'd like to write a DIP on this someday (note that this does not mean I am suggesting D array indexes to optionally start from values different from 0. I am referring just to types, and enumerations are could be not supported).

Bye,
bearophile

Any reason why this needs language support? I haven't tried it, but I can't see why it can't be trivially done in a library.

Pascal example:

type
  colors = (red, blue, yellow);

var
  pallete : array colors of integer;

begin
 pallete[red] := 4;
end



You want a compiler error if the index is invalid and bounds checking when iterating over the enumeration and using it as indexes.

Probably possible with some heavy duty compile time metaprogramming, not sure about the quality of possible error messages and if it would cover all scenarios Pascal and Ada allow for.

--
Paulo

Reply via email to