考虑这个结构
template<std::size_t... a>
struct A{};
如何连接两个类型化的可变参数模板参数?
concat<A<1,2,3>, A<4,5,6,7>> // should be of type A<1,2,3,4,5,6,7>
您可以通过处理的实例化的特殊化来实现A
。
template<typename...>
struct concat_impl; // just a declaration, to allow for specializations
template<std::size_t... s1, std::size_t... s2>
struct concat_impl<A<s1...>, A<s2...>> { // specialize
using type = A<s1..., s2...>; // concatenate
};
以及方便的别名,以免在typename
任何地方都要说。
template<typename A1, typename A2>
using concat = typename concat_impl<A1,A2>::type;
这是一个演示
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句