constexpr function can be used at places where compiler can not decide to evaluate at compile time. Whereas if we want to force evaluate the function at compile time, we can use consteval keyword as shown below.
consteval int max(int a, int b)
{
return a < b ? b : a;
}If we invoke this function like:
int arg{1};
std::cout << max(2, arg);the compilation fails (unlike constexpr function that gets compiled).
References
- [ ]