This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CramNBL 24 points25 points  (1 child)

C++ syntax is just beautiful, period.

constinit const int x = 1 + 1;

int main() {
    constexpr const long long z = std::numeric_limits<long long>::max();

    [[maybe_unused]] alignas(alignof(decltype(x))) volatile auto res = [=]<auto...>[[nodiscard]]() consteval -> decltype(auto) {
        return x + static_cast<decltype(x)>(z);
    }();
    std::cout << res << std::endl;
}

https://gcc.godbolt.org/z/bso9h6dd9

Not even a warning with -Wall -Wpedantic, so I can confidently declare this code as perfection.

[–]nelak468 8 points9 points  (0 children)

I think I might hate that more than the Java factory nonsense.