Compile time function execution...

BCS BCS at pathlink.com
Thu Feb 15 11:36:43 PST 2007


Ary Manzana wrote:
> BCS escribió:
> 
>> Ary Manzana wrote:
>>
>>> A question: is there anyway the compiler can tell the user if a 
>>> certain function can be executed at compile time? Those six rules may 
>>> be hard to memorize and while coding sensitive code it would be great 
>>> to ask the compiler "Is the function I'm writing can be executed at 
>>> compile time?". Otherwise it's just a guess.
>>
>>
>> int[foo()] should do it, I think, or temp!(foo()).
>>
>> Both hack, but...
> 
> 
> It would be nice to have something like this in phobos:
> 
> -------------------------------------------------
> import ... ?
> 
> int square(int i) { return i * i; }
> 
> static assert (isCompileTimeExecution(square());
> -------------------------------------------------
> 
> so that if the function is changed you can still assert that or know 
> that you've lost it.

I'd go with an is expression

is(square(int) : const)

sort of in line with the function/etc. stuff.



More information about the Digitalmars-d mailing list