Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is D's "static if" declarative or procedural?

Consider the following code:

static if (!is(MyStruct))
{
    struct MyStruct
    {
    }
}

static if (is(MyStruct))
{
    static assert(0);
}

My original understanding has been that the order of declarations (in global scope) does not matter in D.

However, in this case, the order of the static ifs makes the difference between whether or not the program compiles.

Is D's compile-time evaluation stage, therefore, a procedural feature (like C/C++), a declarative feature, or something else? What is it currently, and what is it planned to be (if the two are different)?


Edit:

I just realized, the problem doesn't even end here. What happens of a static if uses .tupleof to enumerate the members of the current module, and create the same type of problem?

like image 928
user541686 Avatar asked Oct 09 '22 15:10

user541686


1 Answers

It's a declarative feature that has procedural properties as a side effect of the implementation.

like image 180
FeepingCreature Avatar answered Oct 13 '22 09:10

FeepingCreature