constexpr vs consteval
constexpr (C++11) suggest compile time “resolution” while consteval (C++20) enforces it
constexpr int foo(int a)
{
return a * 2;
}
consteval int bar(int a)
{
return a * 2;
}
int
main(int __attribute__((unused)) argc,
char __attribute__((unused)) *argv[],
char __attribute__((unused)) *envp[])
{
int a;
std::cin >> a;
foo(a);
foo(3);
// bar(a); does not compile
bar(3);
return 0;
}
constexpr object requires static initialization and constexpr destruction