Compile time function execution...

Dave Dave_member at pathlink.com
Fri Feb 16 11:32:15 PST 2007


Walter Bright wrote:
> torhu wrote:
>> Walter Bright wrote:
>>> This should obsolete using templates to compute values at compile time.
>>
>> Wonderful feature, but look at this:
>>
>> int square(int x)
>> {
>>    return x * x;
>> }
>>
>> const int foo = square(5);
>>
>> al_id4.d(6): Error: cannot evaluate (square)(5) at compile time
>>
>>
>> I was hoping this would make some C macros easier to replace, without 
>> needing template versions for initializing consts.
> 
> Aggh, that's a compiler bug.
> 
> int foo = square(5);
> 
> does work. I knew I'd never get it right the first try :-(

Wait -- int foo = square(5); is supposed to CTFE? If so that'd be awesome.



More information about the Digitalmars-d mailing list