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: nob...@puremagic.com
        ReportedBy: rsi...@gmail.com


--- Comment #0 from Shin Fujishiro <rsi...@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: -------

Reply via email to