constexpr auto value
📝 C++This C++ snippet declares a constexpr variable named value that is evaluated at compile time for constant expressions.
C++
constexpr auto value = []() { return 42;
}();
Comments
Yeah, constexpr is great for compile-time evaluation, but watch out - if you try to use it in a context that requires a runtime value, like a function parameter passed by reference, the compiler might silently fall back to runtime. Have you run into cases where that caught you off guard?