Compile time function execution...

Reiner Pope xxxx at xxx.xxx
Thu Feb 15 21:09:13 PST 2007


Bill Baxter wrote:
> Walter Bright wrote:
>> Walter Bright wrote:
>>> This should obsolete using templates to compute values at compile time.
>>
>> For contrast, compare with the C++ proposal:
>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1972.pdf
> 
> It's kinda long and boring, but it looks like the key differences are
> 
> 1) The need to tag compile-time functions with a new keyword, 
> "constexpr", though they seem to sell this as an advantage.  "a 
> programmer can state that a function is intended to be used in a 
> constant expression and the compiler can diagnose mistakes." -- page 9.
> 
Would this be useful as an optional tag? Suppose you wanted to make a 
utils library that was usable in both compile-time and run-time form. 
You write your code trying to follow the rules supplied in the specs, 
but how do you make sure you haven't slipped up anywhere? Would an 
additional keyword help here, or do you just have to do all your 
unit-tests in static form, eg:

char[] itoa(long value) {...}

unittest
{
     static assert(itoa(12345) == "12345");
}

I suppose there'e not much incentive to add a keyword in this situation, 
but perhaps it could be useful elsewhere?

Cheers,

Reiner



More information about the Digitalmars-d mailing list