foreach over split string

Jonathan M Davis jmdavisProg at gmx.com
Wed Jul 17 10:59:59 PDT 2013


On Wednesday, July 17, 2013 16:02:00 JS wrote:
> foreach(n; std.string.split(s, ","))
> {
> // n can't be read at compile time
> }
> 
> using in a ctfe.
> 
> How to loop over a string array in a ctfe?

I would point out that if you're just splitting a string to iterate over it, 
then you should probably use std.algorithm.splitter, as it avoids allocating a 
new array.

But the code that you have here appears to work just fine in CTFE for me, so 
you probably have something else going on in code that you didn't show which 
is making it so that CTFE isn't working for you.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list