这段代码在g ++(coliru)中编译得很好,但不能编译MSVC(godbolt和我的VS2017)。
模板< class T> void f(){ constexpr bool b = std :: …
如何在保持编译时保证的同时解决它?
标记 constexpr bool 如 static 作为一种解决方案。
constexpr bool
static
看到 的 演示 强>
或者,您可以使用中的条件 if constexpr 而不是将其分配给 bool 。如下所示:
if constexpr
bool
if constexpr(std::is_same_v<T,int>)
请注意,MSVC提出了一些错误 constexpr 变量捕获。 其中之一是: 的 在lambda中捕获constexpr的问题 强> 另一个是: 的 如果constexpr在lambda 强>
constexpr