[Issue 5034] New: Ranged (or bounded) array initializer
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Oct 10 13:40:14 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5034
Summary: Ranged (or bounded) array initializer
Product: D
Version: D2
Platform: Other
OS/Version: Other
Status: NEW
Keywords: spec
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: rsinfu at gmail.com
--- Comment #0 from Shin Fujishiro <rsinfu at gmail.com> 2010-10-10 13:39:45 PDT ---
When creating certain kind of tables, people often do the following brute-force
to fill some ranges in static arrays as follows:
enum CharType { none, digit, alpha, punct }
static immutable CharType[char.max + 1] toCharType =
[
/* 0 1 2 3 4 5 6 7 8 9 */
0,0,0,0,0,0,0,0,0,0,
...snip...
0,0,0,0,0,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
...snip...
];
It's very bug-prone and hard to maintain. So, for such kind of range-filling
initialization, I propose the following more clean syntax:
static immutable CharType[char.max + 1] charTypes =
[
// [new syntax] ranged initializers
'0' .. '9'+1: CharType.digit,
'A' .. 'Z'+1: CharType.alpha,
'a' .. 'z'+1: CharType.alpha,
// usual initializer
':': CharType.punct
];
Does it look good? As for this problem, I think CTFE doesn't much help - the
above syntax is very clean and intuitive.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list