如何在void上实现部分专用模板与定义分开
How to implement partial specialized template on void separate from definition?
我在具有部分专业的同时将内部类的实现分开时有问题。这是一个示例代码,可以说明我的问题:
#include <type_traits>
template <typename T>
using enable_if_copyable = std::enable_if_t<std::is_copy_constructible<T>::value>;
template <typename T>
using enable_if_not_copyable = std::enable_if_t<!std::is_copy_constructible<T>::value>;
template <typename T, typename Enabled=void>
struct Foo;
template <typename T>
struct Foo<T, enable_if_copyable<T>>
{
struct Bar
{
Bar();
};
};
template <typename T>
struct Foo<T, enable_if_not_copyable<T>> {
struct Bar
{
Bar();
};
};
template <>
struct Foo<void,void>
{
struct Bar
{
Bar();
//Bar() {} This compiles, but it is not what I want.
};
};
template <typename T>
Foo<T, enable_if_copyable<T>>::Bar::Bar()
{}
template <typename T>
Foo<T, enable_if_not_copyable<T>>::Bar::Bar()
{}
template <>
Foo<void, void>::Bar::Bar() // this does not compile
{}
int main() {
Foo<int>::Bar b;
Foo<void>::Bar v;
}
由于依赖关系,我必须在声明之外实施Bar
的C'1。我的问题是所有编译器(Clang,GCC,Visual Studio 2015)都抱怨class Foo<void, void>
声明之外的Foo<void, void>::Bar::Bar() {}
实现。如果我在void
上的专业化中实现Bar
的C'4,我没有任何问题。这不是可行的还是可以帮助我发现问题的人?非常感谢!
尝试删除 template<>
;我的意思是:
// template <>
Foo<void, void>::Bar::Bar() // now compile
{}
有关更多详细信息,请参见此页面。
相关文章:
- 在 C++20 中是否不再允许在 std 中对程序定义类型的函数模板进行专用化?
- C++模板专用化 - 无法匹配函数定义
- 如何使用 STL 排序对具有模板专用化的自定义类对象进行排序?
- 为什么模板专用化需要内联定义?
- 模板专用化会导致未定义的引用错误
- 对专用模板成员的未定义引用
- 在模板类内部定义的枚举上的嵌套类的部分专用化
- 没有针对完全专用模板类的外联虚拟方法定义
- 使用模板模板参数进行模板定义的函数专用化
- 如何从具有专用化的类模板定义静态成员变量?
- 如何为模板化类的模板化函数定义模板专用化
- C++模板专用化成员函数的定义
- 仅为某些模板专用化定义转换运算符:预期类型/预期类型说明符
- 如何在另一个类模板中定义完全专用类的构造函数
- C++跨文件共享的模板专用化定义
- 为类模板的单个成员定义专用化
- UE4自定义专用服务器(碰撞,命中框)
- 定义专用模板类构造函数时避免重复
- boost:enable_if 在模板化类中定义专用方法
- 定义专用类的不完整结构