Defining a static array with values in a range

tcak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 22 01:26:20 PST 2015


On Thursday, 22 January 2015 at 07:29:05 UTC, anony wrote:
> On Thursday, 22 January 2015 at 05:56:40 UTC, tcak wrote:
>> I want to define alphanumeric characters in an easy way. 
>> Something like that:
>>
>> char[] arr = ['a'..'z', 'A'..'Z', '0'..'9'];
>>
>> Though above example doesn't work. Is there any easy way to do 
>> this?
>>
>> I am trying to do something like EBNF definitions. So, I do 
>> not want to use loops, or define every single thing one by one 
>> by hand.
>
> There are convenient constants defined in std.ascii.
>
> import std.ascii;
> string arr = lowercase ~ uppercase ~ digits;
>
> // also 'std.ascii.letters' gives ('A' .. 'Z' ~ 'a' .. 'z')

Well, that's just disguising what we can't do.

D has alot of compile time structures, even much complex than 
what I asked. So, this type of thing should be doable for 
immutable arrays.


More information about the Digitalmars-d-learn mailing list