提问人:Danny 提问时间:11/4/2023 更新时间:11/4/2023 访问量:82
C++20,有没有 constexpr 替代 'std::is_constant_evaluated()'?
C++20, is there a constexpr alternative to `std::is_constant_evaluated()`?
问:
我知道这不能在通话中正确使用。std::is_constant_evaluated
if constexpr
在编译时,是否有类似的方法可以区分函数中的路径和非路径?我经常发现自己想要这种模式:constexpr
constexpr
constexpr auto MyFunc()
{
if (!std::is_constant_evaluated())
{
return Type();
}
else{
return OtherType();
}
}
但是,由于这不是条件,因此此函数无法使用不同的自动扣除返回类型进行编译。到目前为止,我的解决方案是每当我遇到这种模式时,只需简单地制作不同名称的函数版本,但我真的希望有一种不那么笨拙的方法。constexpr
constexpr
答: 暂无答案
下一个:串联和乘以幻数的问题。C++语言
评论