更新:
我在visualstudio.com上提交了一份错误报告.
所以我开始涉及C++的模板,当我试图阻止使用模板类进行编译时遇到了这个问题static_assert.
基本上,static_assert当使用C++语言标准在ISO20 + 17标准版(/ std:c ++ 17)中使用VS2017上的lambda内部时,不会触发错误.
我也在gcc-7上使用-std = c ++ 17尝试了这个,并且触发了错误.这是VS2017上的一个错误还是我缺少的东西?
代码示例:
#include <iostream>
#include <string>
#include <type_traits>
template<typename T, typename Enable = void>
class IntegralContainer
{
static_assert(std::is_integral<T>::value, "Type must be an integral!");
};
template<typename T>
class IntegralContainer<T, typename std::enable_if< std::is_integral<T>::value >::type >
{
private:
T _value;
public:
IntegralContainer(T value)
: _value(value)
{
}
};
int main()
{
IntegralContainer<int> int_container(1);
// static_assert message is shown here. …Run Code Online (Sandbox Code Playgroud)