Hello Mike,

I'm trying to compile the following file. Can somebody explain to me
how I can rewrite it so that I don't get "Error: non-constant
expression"? All I'm trying to do is create, using templates, a string
of all characters between two given characters:


1) where did you get that error? (I'm lazy, sorry)
2) is there a reason you don't use CTFE?

dchar[] Between(dchar start, dchar stop)
{
 if(start > stop) { auto t = start; start = stop; stop = t; }

 dchar[] ret;
 for(dchar d = start; d<=stop; d++) ret ~= d;
 return ret;
}

import std.stdio;
void Go(dchar[] s)(){writef("%s\n", s); }
void main(){Go!(Between('a','g'))();}

1 module ua;
2
3 template dcharInterval(immutable(dchar) start, immutable(dchar)
stop)
4 {
5    static assert(stop >= start);
6    static if(start == stop)
7       dstring dcharInterval = [start];
8    else
9       dstring dcharInterval = [start] ~ dcharInterval!(start + 1,
stop);
10 }
11
12 dstring LATIN = "\u00AA"d ~ "\u00BA"d ~ dcharInterval!(0x00C0,
0x00D6);
13
Thanks.

--
... <IXOYE><



Reply via email to