On Sunday, 13 August 2017 at 08:09:28 UTC, Petar Kirov [ZombineDev] wrote:
On Sunday, 13 August 2017 at 07:37:15 UTC, data pulverizer wrote:
Hi all,

Is it possible to launch/spawn a thread/fibre or some other appropriate item and obtain an immutable/enum or some appropriate output at compile-time? For instance return an immutable(string) from the external thread to be used as the input to a template parameter or a CTFE function. To be clear the thread carries out run-time processing e.g. reading a file.

Thanks in advance.

No, CTFE is single-threaded and additionally it is required that functions executed at compile-time are "pure", i.e. they don't affect the global state of the system and don't use any non-portable facilities. Essentially, only pure computation is allowed.

Though, specifically reading files is allowed at compile-time via the `string s = import("file.txt");` syntax, provided that the file `file.txt` is located in a directory, specified to the compiler by the `-J` flag. For more information see:
http://dlang.org/spec/expression.html#import_expressions

Thank you. Great explanation!

Reply via email to