小编Eye*_*seo的帖子

在g ++ 4.8.1中使用enum的enable_if

我想使用基于带有g ++的枚举的SFINAE.

使用g ++(4.8.1)编译时出错:
error: no type named ‘type’ in ‘struct std::enable_if<false, void>’

clang(3.2)编译它没有那个错误.

(a2和b2在两种情况下都会导致编译错误!)

编辑:
正如Sharth 回答的那样,代码是错误的,而clang 3.2只是"很好".
是否有不同的方法来实现此功能?


#include <type_traits>

enum Foo {
  A = 3,
  B = 4
};

template<Foo T> class Bar {
  const Foo foo_;

public:

  Bar() : foo_(T) {}

  template<typename = typename std::enable_if<T == A>::type>
  Bar(int x, int y, int z) : foo_(T) {}


  template<typename = typename std::enable_if<T == B>::type>
  Bar(int x, int y, int z, int w) : foo_(T) {}

  ~Bar() {} …
Run Code Online (Sandbox Code Playgroud)

c++ enums templates g++ clang

2
推荐指数
1
解决办法
993
查看次数

标签 统计

c++ ×1

clang ×1

enums ×1

g++ ×1

templates ×1