dirEntries within static foreach: memory.d(827): Error: fakePureErrno cannot be interpreted at compile time, because it has no available source code
    kdevel 
    kdevel at vogtner.de
       
    Mon Feb 11 01:05:05 UTC 2019
    
    
  
On Monday, 11 February 2019 at 00:54:27 UTC, Seb wrote:
> On Monday, 11 February 2019 at 00:19:02 UTC, kdevel wrote:
[...]
> You can't read or list files at compile-time.
dmd can read files at compile time using the import function [1]
> What are you trying to do?
Incorporate HTML template files into a CGI binary. After putting 
[ and ] around the list in LS this works:
```TemplateStore.d
module TemplateStore;
import std.path;
import std.conv;
import std.file;
immutable string[string] template_map;
static this ()
{
    immutable LS = import (`LS`);
    immutable template_files = mixin(LS);
    static foreach (f; template_files) {
       pragma (msg, `reading template <` ~ f ~ ">");
       template_map[f] = import (f);
    }
}
```
[1] 
https://forum.dlang.org/thread/njnwacxnvxlwlpjcuyud@forum.dlang.org
    
    
More information about the Digitalmars-d-learn
mailing list