Hacker News new | ask | show | jobs
by gumby 1122 days ago
I wish constexpr actually asked the compiler to evaluate an expression at compile time and not just a statement.
1 comments

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.)
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.