c++ - Visual Studio 2013 模板别名

标签 c++ c++11 visual-studio-2013 template-aliases

下面的代码

template <class Integral>
using enable_if_integral_t = typename std::enable_if<std::is_integral<Integral>::value>::type;

template <class Integral, class Enable = void>
class DigitsNumber;

template <class Integral>
class DigitsNumber<Integral, enable_if_integral_t<Integral>>{
};

在 MSVC 2013 中生成错误:

error C3203: 'enable_if_integral_t' : unspecialized alias template can't be used as a template argument for template parameter 'Enable', expected a real type

但在 gcc 中编译良好。

此代码是否符合 C++11 标准,以及 Visual Studio 错误/未实现的功能,或者它不符合标准,而是 gcc 扩展。

有什么方法可以让这个在 VS 中工作吗?

谢谢。

最佳答案

我能够使用 link 解决这个问题那dyp提供:

template <class Integral>
struct MSVCWorkaround : std::enable_if<std::is_integral<Integral>::value, SomeType> {};

template <class Integral>
using enable_if_integral_t = typename MSVCWorkaround<Integral>::type;

关于c++ - Visual Studio 2013 模板别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20828846/

相关文章:

c++ - 无锁单一生产者/单一消费者循环缓冲区

c++ - 使用可变参数模板展开序列范围

c# - Visual Studio 2013 中的 ASP.NET 网站模板等效吗?

visual-studio - Visual Studio 在断言失败时退出,没有错误消息

c++ - open() 函数的 _sopen_s() 等价物是什么?

c++ - Devil库使用中的错误

c++ - 将除字符串以外的所有类型按值传递给模板函数

c++ - 通过对象访问类子类型

c++ - Trilinos - C++ : error trying to exec 'cc1plus' : execvp: No such file or directory

c++ - 为什么我们在 Visual Studio 2013 中引用 C++ 项目?