<分区>
请看下面的代码:
#include <iostream>
constexpr int f(int a, int b)
{
return a<b? a : throw std::out_of_range("out of range");
}
int main()
{
try
{
int n = 0;
f(5, n);
}
catch(const std::exception& ex)
{
std::cout<<"Exception caught"<<std::endl;
std::cout<<ex.what()<<std::endl;
}
}
我知道 constexprt 函数是在编译时处理的。那么我怎么可以将“运行时”本地变量传递给它并在运行时再次在 try-catch block 中使用它呢?也许我缺少 smth regargind constexprt 函数?