Hacker News new | ask | show | jobs
by WalterBright 1118 days ago
In D, every part of the grammar that is a constant-expression must be compiled at compile time. For example:

    void test() {

    int square(int y) { return y * y; }
    int x = square(3);  // evaluate at square at run time
    enum y = square(3); // evaluate at square compile time

    }
(Although, when the optimizer gets through inlining square(), etc., it will wind up at compile time anyway.)
1 comments

I think a compliant c++ implementation is allowed to do this and I think all do so at least for straightforward cases.
It's allowed to but you aren't allowed to assume.