我可以基于 constexpr if 编译失败吗?

问题描述 投票:0回答:0

是否有解决方法来做这样的事情?

if constexpr (std::floating_point<T>) {}
else if constexpr (std::integral<T>) {}
...
else static_failure("Feature expansion needed");

因为如果我用

static_failure
替换
static_assert
,它需要复制上述所有条件(它们又多又复杂)并且变得丑陋。

我不喜欢这样的运行时行为:

throw "Feature expansion needed";
c++ static-assert
© www.soinside.com 2019 - 2024. All rights reserved.