联合类型的模板专业化
Template specialization for union type
我如何专业化union
类型的模板?假设我有模板功能
template <typename T>
void foo(T value);
如果T
不是任何union
类型,我想禁止调用此功能。我该如何实现?
如果T不是任何联合类型,我想禁止调用此功能。我该如何实现?
也许使用std::is_union
?
template <typename T>
std::enable_if_t<std::is_union<T>::value> foo(T value)
{ /* ... */ }
您可以将std::enable_if
(std::enable_if_t
(与std::is_union
中的CC_7一起使用。类似:
template <class T,
typename std::enable_if_t<std::is_union<T>::value,
int> = 0>
void foo(T t) {
// an implementation for union types
}
这是Sfinae规则的解释。
相关文章:
- C++模板 - 浮动和积分类型的不同专业化
- 任何指针类型的模板专业化
- 编写完整专业化以识别void类型的问题
- 调用每种类型的变异模板的正确模板专业化
- 我该如何允许类型的对象非专业化并在不使用指针的情况下识别何时是这种情况
- 非类型的模板专业化
- 我们可以专业化类模板的枚举(类型)成员吗?
- 使用声明类型选择函数专业化
- 联合类型的模板专业化
- 对于类型是类模板专业化的参数,ADL背后的理由是什么
- 类型和非型模板专业化
- C - 具有非类型模板参数的模板类上的专业化函数模板
- GCC 7 没有选择正确的类型特征专业化
- 特定模板类型的功能模板专业化
- Clang无法在模板类专业化中编译模板功能,该模板类专业化与模板声明具有 *不同的返回类型 *
- 对于需要其他模板参数的类型函数的部分模板专业化
- 统一功能使用模板专业化和接口来调用实例和原始类型
- 指针作为函数返回类型的部分专业化
- 忽略了部分功能专业化中价值类型的最高级别const预选赛
- 在基元类型模板专业化之间转换