簡體   English   中英

連接兩個類型化的可變參數模板包

[英]Concatenate two typed variadic template packs

考慮這個結構

template<std::size_t... a>
struct A{};

如何連接兩個類型化的可變參數模板 arguments?

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;

這是一個演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM