g++ 7.1.1 中的可变参数模板部分特化"not more specialised"
Variadic template partial specialisation "not more specialised" in g++ 7.1.1
>我有一个等价物std::integer_sequence
(我们还没有使用C++14(。我还有两个帮助程序类,用于删除或添加前导数字。
// Sequence type
template <typename Type, Type ... Values>
struct Sequence
{
using value_type = Type;
};
// Pop a value off of the start of a sequence
template <class Class>
struct SequencePop;
template <typename Type, Type Value, Type ... Values>
struct SequencePop<Sequence<Type, Value, Values ...>>
{
using type = Sequence<Type, Values ...>;
};
// Push a value on to the start of a sequence
template <class Class, typename Class::value_type Value>
struct SequencePush;
template <typename Type, Type Value, Type ... Values>
struct SequencePush<Sequence<Type, Values ...>, Value>
{
using type = Sequence<Type, Value, Values ...>;
};
SequencePop
在我尝试过的所有编译器(g++ 6.4.1,g++ 7.1.1,clang++ 4.0.1(中都被认为是有效的。SequencePush
不能使用 g++ 7.1.1 进行编译。错误消息如下所示。
test.cpp:24:8: error: partial specialization ‘struct SequencePush<Sequence<Type, Values ...>, Value>’ is not more specialized than [-fpermissive]
struct SequencePush<Sequence<Type, Values ...>, Value>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:21:8: note: primary template ‘template<class Class, typename Class::value_type Value> struct SequencePush’
struct SequencePush;
g++ 7.1.1 拒绝此代码是否正确,如果是,如何判断SequencePush
不比主模板"更专业"?
它应该是
template <typename Type,
Type ... Values,
typename Sequence<Type, Values ...>::value_type Value>
struct SequencePush<Sequence<Type, Values ...>, Value>
{
using type = Sequence<Type, Value, Values ...>;
};
演示
因为Class::value_type
和Sequence<Type, Values ...>
Type
不是"相关的"。
事实上,通用模板SequencePush
由一个模板参数(Class
(参数化,但您的专业化由两个(Type
和Value
(参数化。在常规模板中,Type
不是参数,因为它是从Class
推导出的。
一个有效但不令人满意的解决方案是:
template <class Class, typename Type, Type Value>
struct SequencePush;
template <typename Type, Type Value, Type ... Values>
struct SequencePush<Sequence<Type, Values ...>, Type, Value>
{
using type = Sequence<Type, Value, Values ...>;
};
演示
相关文章:
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- 使用JsonCpp将数据返回到带有pybind11的python会在python调用中产生Symbol not foun
- OpenCV Android C++ imwrite not found
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 使用单词"not"作为C ++类的名称会导致VS2019错误
- 错误"Could not find Boost"(缺少:上下文标头)
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 套接字连接"Operation not permitted"错误,甚至使用升压/平发器根.cpp
- Is !NaN not a NaN?
- 为什么我会" void value not ignored as it ought to be"?
- 解决"ld: library not found for -ltensorflow_framework.2.3.0"
- 加载与引用 .NET DLL 位于同一文件夹中的引用的 .NET DLL 时"Not found"异常
- Directx 11 - CompileFromFile() is not compiling
- 方法错误"not all control paths return a value"和方法不返回值
- Centos7 g++ "to_string is not in a member of std"
- 将系数存储在头文件的数组中("does not name a type"错误)
- QGraphicsItems not showing up QGraphicsScene
- 在调试模式下引发C++ "deque iterator not dereferencable"异常
- InitializeCriticalSectionEx Not Located In KERNEL32.Dll
- g++ 7.1.1 中的可变参数模板部分特化"not more specialised"