Re: Forcing compile time evaluation of pure functions

2011-07-14 Thread bearophile
> In GCC there is a way to (sometimes) do it, see the __builtin_constant_p here: > http://www.delorie.com/gnu/docs/gcc/gcc_81.html Google code search gives about 8,100 answers: http://www.google.com/codesearch#search/&q=%22__builtin_constant_p%22&type=cs Bye, bearophile

Re: Forcing compile time evaluation of pure functions

2011-07-14 Thread bearophile
scarrow: > I'd really like to figure out how to have Hash("foo") be static and > Hash(variable) be dynamic. In GCC there is a way to (sometimes) do it, see the __builtin_constant_p here: http://www.delorie.com/gnu/docs/gcc/gcc_81.html Time ago I have asked for something similar in D too, becaus

Re: Forcing compile time evaluation of pure functions

2011-07-14 Thread scarrow
I think invoking a template to call the pure function (StaticEval!(Hash("foo")) isn't much different from StaticHash!("foo"). You still have to explicitly know whether you're dealing with a compile time constant or not. I'd really like to figure out how to have Hash("foo") be static and Hash(vari

Re: Forcing compile time evaluation of pure functions

2011-06-30 Thread Simen Kjaeraas
On Thu, 30 Jun 2011 07:11:44 +0200, scarrow wrote: Hey all, I'd like to embed hashed strings into my code. The C++ version of this engine ran an external tool to preprocess the files. In D my strongly pure function is only evaluated if I assign it to something like an enum or invoke it

Re: Forcing compile time evaluation of pure functions

2011-06-30 Thread bearophile
scarrow: > Annoyingly, however, I can't do the following at compile time: > > f(Hash("foo")); > > I'm not sure what the point is in distinguishing between these two cases. Walter has decided that he doesn't like the D compiler to arbitrary run at compile time arbitrary long to run code. Th

Re: Forcing compile time evaluation of pure functions

2011-06-29 Thread scarrow
Oh, I also wanted to mention that although ideally I'd be able to invoke the compile time and runtime versions identically and have it automatically select, I'm also worried about accidentally invoking the runtime version when I should have been using the compile time version. I can't think of a w

Forcing compile time evaluation of pure functions

2011-06-29 Thread scarrow
Hey all, I'd like to embed hashed strings into my code. The C++ version of this engine ran an external tool to preprocess the files. In D my strongly pure function is only evaluated if I assign it to something like an enum or invoke it from a template. So the following generate compile time has