gpt4 book ai didi

c++ - 我可以使用 foo 这样的模式部分特化模板吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:28:26 26 4
gpt4 key购买 nike

如果可能的话,可以在不递归的情况下索引可变参数模板参数包。但是,GCC 是 refusing to pick up my partial specialization这里:

template <int I, typename List>
struct element_impl;

template <typename... TL, int... IL, typename T, int I, typename... TR, int... IR>
struct element_impl<I, typelist<pair<TL,IL>..., pair<T,I>, pair<TR,IR>...>> {
typedef T type;
};

prog.cpp: In instantiation of 'element<0, typelist<int, double, char,
float, long int> >
':
prog.cpp:52:34: instantiated from here
prog.cpp:47:79: error: invalid use of incomplete type 'struct element_impl<0, typelist<pair<int, 0>, pair<double, 1>, pair<char, 2>, pair<float, 3>, pair<long int, 4> >'

GCC 有问题,还是我忽略了可变参数模板的某些限制?

最佳答案

规范说在 14.8.2.5p9

If P has a form that contains <T> or <i>, then each argument Pi of the respective template argument list P is compared with the corresponding argument Ai of the corresponding template argument list of A. If the template argument list of P contains a pack expansion that is not the last template argument, the entire template argument list is a non-deduced context.

你的 typelist<T>不幸的是匹配那个模式。

关于c++ - 我可以使用 foo<T..., int, U...> 这样的模式部分特化模板吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11073423/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com