On Saturday, 11 June 2016 at 13:03:47 UTC, ketmar wrote:
On Friday, 10 June 2016 at 18:47:59 UTC, Joerg Joergonson wrote:
In any case, this is impossible. D has no such concept as
"compile-time-only" values, so any usage of a value risks
embedding it into the binary.
sure, it has.
template ParseData (string text) {
private static enum Key = "XXXyyyZZZ33322211\n";
private static enum TRet = "int data = 3;";
private static enum FRet = "int data = 4;";
static if (text.length >= Key.length) {
static if (text[0..Key.length] == Key)
enum ParseData = TRet;
else
enum ParseData = FRet;
} else {
enum ParseData = FRet;
}
}
void main () {
mixin(ParseData!(import("a")));
}
look, ma, no traces of our secret key in binary! and no traces
of `int data` declaration too!
This doesn't seem to be the case though in more complex examples
;/ enums seem to be compile time only in certain conditions. My
code is almost identical do what you have written except
ParseData generates a more complex string and I do reference
parts of the "Key" in the generation of the code. It's possible
DMD keeps the full code around because of this.