相关疑难解决方法(0)

部分专业化消歧优先链的更好模式?

考虑以下系列的部分专业化:

template <typename T, typename Enable=void>
struct foo {
  void operator()() const { cout << "unspecialized" << endl; }
};

template <typename T>
struct foo<T, enable_if_t<
  is_integral<T>::value
>>{
  void operator()() const { cout << "is_integral" << endl; }
};

template <typename T>
struct foo<T, enable_if_t<
  sizeof(T) == 4
    and not is_integral<T>::value
>>{
  void operator()() const { cout << "size 4" << endl; }
};

template <typename T>
struct foo<T, enable_if_t<
  is_fundamental<T>::value
    and not (sizeof(T) == 4)
    and not is_integral<T>::value
>>{ …
Run Code Online (Sandbox Code Playgroud)

c++ templates idioms partial-specialization

5
推荐指数
1
解决办法
227
查看次数

标签 统计

c++ ×1

idioms ×1

partial-specialization ×1

templates ×1