dav*_*ide 8 c++ instantiation static-assert constexpr if-constexpr
static_assert在 的 false 分支中应丢弃以下内容if constexpr,但由于断言失败而导致编译失败:
#include <type_traits>
template <class T>
constexpr bool f() {
if constexpr (std::is_same<T, int>::value) return true;
else static_assert(false, "message");
}
int main () {
if constexpr (f<int>()) return 1;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我希望丢弃的分支if constexpr不会被评估,因为它f是用 type 实例化的int。
用 Gcc 7.2 (-std=c++17) 编译
| 归档时间: |
|
| 查看次数: |
1868 次 |
| 最近记录: |