Why CTFE is context-sensitive?

Timon Gehr timon.gehr at gmx.ch
Sun Jan 26 16:24:08 PST 2014


On 01/26/2014 04:06 PM, Pierre Talbot wrote:
> On Sunday, 26 January 2014 at 13:48:47 UTC, Timon Gehr wrote:
>> On 01/26/2014 10:59 AM, Pierre Talbot wrote:
>>> Hi,
>>>
>>> I was wondering why CTFE is context sensitive, why don't we check
>>> every expressions and run the CTFE if it applies?
>>
>> When does it apply?
>
> According to http://dlang.org/function.html#interpretation
>
> * initialization of a static variable
> * dimension of a static array
> * argument for a template value parameter
>

* initializer of 'enum' constant.

* argument to pragma(msg, ...)

* argument to string mixin

* static if condition

* static assert condition

* Length of fixed-length array

* Index and slice indices into template argument list

* ...

> As shown in the examples:
>
> int square(int i) {
>    return i * i;
> }
>
> void foo() {
>    writeln(square(4)); // run time
> }

This is what we are already doing, so it makes no sense to ask why we 
don't do it. I was asking what would be the alternative criterion.


More information about the Digitalmars-d-learn mailing list