【问题标题】:Inserting any number of types into a pack of template arguments将任意数量的类型插入到一组模板参数中
【发布时间】:2015-02-27 13:05:50
【问题描述】:

InsertTypes<Pack, P<Ts...>, Is...>::type 是类型 Ts... 分别插入位置 Is... 的 Pack。 例如,

InsertTypes<Pack<int, double, char, long, int>, Pack<short, float, std::string>, 2,4,1>::type,

Pack<int, std::string, double, short, char, long, float, int

(在double和char之间插入short,在long和int之间插入float,在int和double之间插入std::string)。

我的方法:先对Is...进行倒序排序(从大到小),对Ts...中的每个类型和Is...中的每个int都应用Insert 为什么要对Is...进行反向排序?因为如果它们不是按那个顺序插入的,那么插入一个类型会使位置偏移一个并弄乱其他插入。但是我的计划有一个缺陷,我稍后会解释。首先让我提供我编写的辅助函数,我测试它们自己可以正常工作:

Insert&lt;T, P&lt;Types...&gt;, N&gt;::type 是包P&lt;Types...&gt;,T 插入位置 N。

template <typename, typename, typename, int> struct InsertHelper;

template <typename T, template <typename...> class P, typename First, typename... Rest, typename... Accumulated>
struct InsertHelper<T, P<First, Rest...>, P<Accumulated...>, 0> {
    using type = P<Accumulated..., T, First, Rest...>;
};

template <typename T, template <typename...> class P, typename First, typename... Rest, typename... Accumulated, int N>
struct InsertHelper<T, P<First, Rest...>, P<Accumulated...>, N> : InsertHelper<T, P<Rest...>, P<Accumulated..., First>, N-1> {};

template <typename, typename, int> struct Insert;

template <typename T, template <typename...> class P, typename... Types, int N>
struct Insert<T, P<Types...>, N> : InsertHelper<T, P<Types...>, P<>, N> {};

现在 ReverseSortIntSequence(使用快速排序):

template <int, typename> struct PrependInt;

template <int N, template <int...> class Z, int... Is>  
struct PrependInt<N, Z<Is...>> {  
    using type = Z<N, Is...>;  
};

template <template<int> class, typename> struct FilterInts;  

template <template<int> class F, template <int...> class Z, int I, int... Is>  
struct FilterInts<F, Z<I, Is...>> {
    using type = typename std::conditional<F<I>::value,
        typename PrependInt<I, typename FilterInts<F, Z<Is...>>::type>::type,
        typename FilterInts<F, Z<Is...>>::type
    >::type;  
};

template <template<int> class F, template <int...> class Z>  
struct FilterInts<F, Z<>> {  
    using type = Z<>;  
};  

template <typename, typename> struct MergeIntSequences;  

template <template <int...> class Z, int... Is, int... Js>  
struct MergeIntSequences<Z<Is...>, Z<Js...>> {  
    using type = Z<Is..., Js...>;
};

template <typename> struct ReverseSortIntSequence;  

template <template <int...> class Z, int N, int... Is>  
struct ReverseSortIntSequence<Z<N, Is...>> {  
    template<int I> struct less_than : std::integral_constant<bool, (I >= N)> {};
    template <int I> struct more_than : std::integral_constant<bool, (I < N)> {};  
    using subsequence_less_than_N = typename FilterInts<less_than, Z<Is...>>::type;
    using subsequence_more_than_N = typename FilterInts<more_than, Z<Is...>>::type; 
    using type = typename MergeIntSequences<typename ReverseSortIntSequence<subsequence_less_than_N>::type,  
        typename PrependInt<N, typename ReverseSortIntSequence<subsequence_more_than_N>::type>::type 
    >::type;
};

template<template <int...> class Z>  
struct ReverseSortIntSequence<Z<>> {  
    using type = Z<>;  
};

现在InsertTypes 自己:

template <typename, typename, typename> struct InsertTypesHelper;

template <typename Pack, template <typename...> class P, template <int...> class Z>
struct InsertTypesHelper<Pack, P<>, Z<>> {
    using type = Pack;
};

template <typename Pack, template <typename...> class P, typename First, typename... Rest, template <int...> class Z, int N, int... Ns>
struct InsertTypesHelper<Pack, P<First, Rest...>, Z<N, Ns...>> : InsertTypesHelper<typename Insert<First, Pack, N>::type, P<Rest...>, Z<Ns...>> {};

template <typename, typename, int...> struct InsertTypes;

template <typename Pack, template <typename...> class P, typename... Types, int... Is>
struct InsertTypes<Pack, P<Types...>, Is...> : InsertTypesHelper<Pack, P<Types...>, typename ReverseSortIntSequence<index_sequence<Is...>>::type> {};

现在,我的测试:

int main() {
    std::cout << std::is_same<
        typename ReverseSortIntSequence<index_sequence<5,10,8,4,0,2,1,2,7,8,3>>::type,
        index_sequence<10,8,8,7,5,4,3,2,2,1,0>
    >::value << std::endl;  // true

    std::cout << std::is_same<
        InsertTypesHelper<Pack<int, double, char, long, int>, Pack<float, short, std::string>, index_sequence<4,2,1>>::type,
        Pack<int, std::string, double, short, char, long, float, int>
    >::value << std::endl;  // true (*)

    std::cout << std::is_same<
        typename ReverseSortIntSequence<index_sequence<2,4,1>>::type,
        index_sequence<4,2,1>
    >::value << std::endl;  // true (**)

    std::cout << std::is_same<
        InsertTypes<Pack<int, double, char, long, int>, Pack<short, float, std::string>, 2,4,1>::type,
        Pack<int, std::string, double, short, char, long, float, int>
    >::value << std::endl;  // false (rats!)
}

我在上面得到了错误,因为尽管上面的 (*) 和 (**) 为真,但我们必须以与 2,4,1 相同的方式排列 Pack&lt;short, float, std::string&gt; 以便以相反的排序顺序获得它。我可以继续进行此修复,但现在它变得过火了。我仍然会继续这样做,但我严重怀疑有更好的方法,可能也相当短。

这里有什么好主意吗?我想提取索引确定的类型对(插入的类型将在这些对之间),但如果原始包中有重复的类型(并且也因为插入的类型),这将不起作用。

更新: 我完成了上面讨论的置换助手,现在一切正常。但是必须有一个比所有这些混乱更好、更短的解决方案。

template <int, typename> struct NthType;

template <int N, template <typename...> class P, typename First, typename... Rest>
struct NthType<N, P<First, Rest...>> : NthType<N-1, P<Rest...>> {};

template <template <typename...> class P, typename First, typename... Rest>
struct NthType<0, P<First, Rest...>> {
    using type = First;
};

template <int, int, typename> struct FindIndexOfIntHelper;

template <int N, int FindMe, template <int...> class Z, int... Rest>
struct FindIndexOfIntHelper<N, FindMe, Z<FindMe, Rest...>> : std::integral_constant<int, N> {};

template <int N, int FindMe, template <int...> class Z>
struct FindIndexOfIntHelper<N, FindMe, Z<>> : std::integral_constant<int, -1> {};  // Not found.

template <int N, int FindMe, template <int...> class Z, int First, int... Rest>
struct FindIndexOfIntHelper<N, FindMe, Z<First, Rest...>> : FindIndexOfIntHelper<N+1, FindMe, Z<Rest...>> {};

template <int FindMe, typename Pack>
using FindIndexOfInt = FindIndexOfIntHelper<0, FindMe, Pack>;

template <typename, typename, typename, typename> struct PermutePackHelper;

template <typename Pack, template <typename...> class P, typename... Accumulated, typename IndicesPack, template <int...> class Z>
struct PermutePackHelper<Pack, P<Accumulated...>, IndicesPack, Z<>> {
    using type = P<Accumulated...>;
};

template <typename Pack, template <typename...> class P, typename... Accumulated, typename IndicesPack, template <int...> class Z, int I, int... Is>
struct PermutePackHelper<Pack, P<Accumulated...>, IndicesPack, Z<I, Is...>> :
    PermutePackHelper<Pack, P<Accumulated..., typename NthType<FindIndexOfInt<I, IndicesPack>::value, Pack>::type>,
        IndicesPack, Z<Is...>> {};

template <typename, typename, typename> struct PermutePack;

template <template <typename...> class P, typename... Types, template <int...> class Z, int... Is, int... Js>
struct PermutePack<P<Types...>, Z<Is...>, Z<Js...>> : PermutePackHelper<P<Types...>, P<>, Z<Is...>, Z<Js...>> {};

【问题讨论】:

  • 如果您要求职位列表按升序排列,这可能会使事情变得更容易。 IE。 1, 2, 4 而不是 2, 4, 1
  • 在将它们传递给下一个实例时,您是否考虑过在大于当前索引的那些索引上加 1,而不是对索引进行排序?
  • @jrok。那么这太容易了:反转索引,然后反转插入类型的包。我喜欢的挑战是不限制用户输入。对于 Dark Falcon,我们只在指数上升时加 1。如果他们上下上下,等等......,那么它就不再那么简单了。
  • 我不明白为什么从大到小做会给出“正确”的答案。之后,与 4 关联的类型不在类型列表中的第 4 位。我猜是在原始列表中的第 4 个元素之后?如果在点 2 插入了多种类型,你会怎么做?没有明确的正确答案,只是一个随意的答案,这表明你的设计存在缺陷。
  • 思考:将types&lt;Ts...&gt; 映射到types&lt;types&lt;Ts&gt;...&gt;。然后插入而不用担心颠簸。然后压扁。

标签: c++ templates c++11 variadic


【解决方案1】:

有一种方法可以使用boost::mpl 来做到这一点,我认为这更容易消化(?)我添加了很多 cmets 来解释这些步骤,并适当的缩进让代码更清晰一些.. . 可能有帮助...

#include <iostream>
#include <type_traits>

#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/sort.hpp>
#include <boost/mpl/comparison.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/next_prior.hpp>
#include <boost/mpl/insert.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/advance.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/transform.hpp>

using namespace boost::mpl;

template <typename R, typename It, typename End>
struct type_inserter
{ 
  // index to insert
  typedef typename deref<It>::type::first KType;
  // type to insert
  typedef typename deref<It>::type::second VType;
  // recurse
  typedef typename type_inserter<
    typename insert<
      R,
      // calculate the location based on the index
      typename advance<typename begin<R>::type, KType>::type,
      VType
    >::type,
    typename next<It>::type,
    End
  >::type type;
};

template <typename R, typename End>
struct type_inserter<R, End, End>
{
  typedef R type;
};

template <typename P>
struct index_access
{
  typedef typename P::first type;
};

struct make_pair
{
  template<typename Kv, typename Pv>
  struct apply
  {
    typedef pair<Kv, Pv> type;
  };
};

template <typename P1, typename P2, int ...I>
struct insert_pack
{
  // transform P2 and indexes
  static_assert(sizeof...(I) == size<P2>::value, "indexes/count P2 mismatch");
  // this iterates through both sequences, constructing a pair and inserting into a vector
  typedef typename transform<vector_c<int, I...>, P2, make_pair, back_inserter<vector0<>>>::type entries;
  // sort the sequence by the index..
  typedef typename sort<entries, greater<index_access<_1>, index_access<_2>>>::type reversed;
  // once sorted, insert the sorted range into the main vector using custom inserter
  typedef typename type_inserter<P1, typename begin<reversed>::type, typename end<reversed>::type>::type type;
};

int main()
{
  typedef vector<int, double, char, long, int> pack1;
  typedef vector<short, float, std::string> pack2;
  // this combines the pack
  typedef insert_pack<pack1, pack2, 2, 4, 1>::type combined;
  // this is what we expect
  typedef vector<int, std::string, double, short, char, long, float, int> packs;
  // sanity check
  BOOST_MPL_ASSERT(( equal< packs, combined> ));
}

【讨论】:

  • 还不熟悉 Boost,但是当我使用 typedef insert_pack&lt;pack1, pack2, 2, 2, 2&gt;::type combined; 运行您的代码时,我得到的结果是 vector&lt;int, double, std::string, float, short, char, long, int&gt;,这也是我的程序给出的(所有类型都插入到位置 2,这迫使它们以相反的顺序出现)。但是,上面的 dyp 指出,稳定的插入应该以非颠倒的顺序出现。我猜这只是口味问题?
  • 我不知道我是否同意,2,2,2的序列表示您处理的每个条目都必须插入位置2,并且该点的序列状态在时间,我不明白这意味着如何在位置 2 插入此范围(以保留顺序),我认为要保留,您需要支持范围插入 - 这是一个不同的(但更容易的问题..)
  • ...如果您采用标准向量并在位置 2 处插入三个条目,您将面临类似的反向序列,这实际上是插入操作的预期行为(它是对序列的独立操作那一点..)我不知道这是否使它更清楚..
【解决方案2】:

这要感谢 Yakk 上面的快速建议。现在我们有了一个不错的优雅解决方案!

#include <iostream>
#include <string>

template <typename, typename, typename, int> struct InsertIntoPackOfPacksHelper;

template <typename T, template <typename...> class P, typename First, typename... Rest, typename... Accumulated>
struct InsertIntoPackOfPacksHelper<T, P<P<First>, Rest...>, P<Accumulated...>, 0> {
    using type = P<Accumulated..., P<T, First>, Rest...>;
};

template <typename T, template <typename...> class P, typename First, typename... Rest, typename... Accumulated, int N>
struct InsertIntoPackOfPacksHelper<T, P<First, Rest...>, P<Accumulated...>, N> : InsertIntoPackOfPacksHelper<T, P<Rest...>, P<Accumulated..., First>, N-1> {};

template <typename, typename, int> struct InsertIntoPackOfPacks;

template <typename T, template <typename...> class P, typename... Types, int N>
struct InsertIntoPackOfPacks<T, P<Types...>, N> : InsertIntoPackOfPacksHelper<T, P<Types...>, P<>, N> {};

template <typename, typename>
struct FlattenPackHelper;

template <template <typename...> class P, template <typename...> class P2, typename... Ts, typename... Us, typename... Rest>
struct FlattenPackHelper<P<Ts...>, P<P2<Us...>, Rest...>> : FlattenPackHelper<P<Ts...>, P<Us..., Rest...>> {};

template <template <typename...> class P, typename... Ts, typename First, typename... Rest>
struct FlattenPackHelper<P<Ts...>, P<First, Rest...>> : FlattenPackHelper<P<Ts..., First>, P<Rest...>> {};

template <template <typename...> class P, typename... Ts, typename... Rest>
struct FlattenPackHelper<P<Ts...>, P<std::string, Rest...>> : FlattenPackHelper<P<Ts..., std::string>, P<Rest...>> {};

template <template <typename...> class P, typename... Ts>
struct FlattenPackHelper<P<Ts...>, P<>> {
    using type = P<Ts...>;
};

template <typename T> struct FlattenPack;

template <template <typename...> class P, typename... Ts>
struct FlattenPack<P<Ts...>> : FlattenPackHelper<P<>, P<Ts...>> {};

template <typename, typename, typename> struct InsertTypesHelper;

template <typename PackOfPacks, template <typename...> class P, template <int...> class Z>
struct InsertTypesHelper<PackOfPacks, P<>, Z<>> {
    using type = PackOfPacks;
};

template <typename PackOfPacks, template <typename...> class P, typename First, typename... Rest, template <int...> class Z, int I, int... Is>
struct InsertTypesHelper<PackOfPacks, P<First, Rest...>, Z<I, Is...>> :
    InsertTypesHelper<typename InsertIntoPackOfPacks<First, PackOfPacks, I>::type, P<Rest...>, Z<Is...>> {};

template <typename, typename, int...> struct InsertTypes;

template <int...> struct index_sequence {};

template <template <typename...> class P, typename... Types, typename... Ts, int... Is>
struct InsertTypes<P<Types...>, P<Ts...>, Is...> {
    using type = typename FlattenPack<typename InsertTypesHelper<P<P<Types>...>, P<Ts...>, index_sequence<Is...>>::type>::type;
};

// Testing
template <typename...> struct Pack {};

int main() {
    std::cout << std::boolalpha << std::is_same<
        InsertTypes<Pack<int, double, char, long, int>, Pack<short, float, std::string>, 2,4,1>::type,
        Pack<int, std::string, double, short, char, long, float, int>
    >::value << std::endl;  // true
}

对于它的价值,这里是与我原来的问题中概述的原始、冗长的解决方案的比较:

#include <iostream>
#include <string>

// ReverseSortIntSequence (using quicksort):
template <int, typename> struct PrependInt;

template <int N, template <int...> class Z, int... Is>  
struct PrependInt<N, Z<Is...>> {  
    using type = Z<N, Is...>;  
};

template <template<int> class, typename> struct FilterInts;  

template <template<int> class F, template <int...> class Z, int I, int... Is>  
struct FilterInts<F, Z<I, Is...>> {
    using type = typename std::conditional<F<I>::value,
        typename PrependInt<I, typename FilterInts<F, Z<Is...>>::type>::type,
        typename FilterInts<F, Z<Is...>>::type
    >::type;  
};

template <template<int> class F, template <int...> class Z>  
struct FilterInts<F, Z<>> {  
    using type = Z<>;  
};  

template <typename, typename> struct MergeIntSequences;  

template <template <int...> class Z, int... Is, int... Js>  
struct MergeIntSequences<Z<Is...>, Z<Js...>> {  
    using type = Z<Is..., Js...>;
};

template <int I, int J>
struct IntLessThan : std::conditional<(I < J), std::true_type, std::false_type>::type {};

template <typename, template <int, int> class = IntLessThan> struct SortIntSequence;  

template <template <int...> class Z, int N, int... Is, template <int, int> class Comparator>  
struct SortIntSequence<Z<N, Is...>, Comparator> {  
    template<int I> struct less_than : std::integral_constant<bool, Comparator<I,N>::value> {};
    template <int I> struct more_than : std::integral_constant<bool, Comparator<N,I>::value || I == N> {};  
    using subsequence_less_than_N = typename FilterInts<less_than, Z<Is...>>::type;
    using subsequence_more_than_N = typename FilterInts<more_than, Z<Is...>>::type; 
    using type = typename MergeIntSequences<typename SortIntSequence<subsequence_less_than_N, Comparator>::type,  
        typename PrependInt<N, typename SortIntSequence<subsequence_more_than_N, Comparator>::type>::type 
    >::type;
};

template<template <int...> class Z, template <int, int> class Comparator>  
struct SortIntSequence<Z<>, Comparator> {  
    using type = Z<>;  
};

// Given Pack, Z<Is...>, Z<Js...>, rearrange Pack in the same way that Z<Is...> is rearranged to get Z<Js...>.  PermutePack will take care of this.
template <int, typename> struct NthType;

template <int N, template <typename...> class P, typename First, typename... Rest>
struct NthType<N, P<First, Rest...>> : NthType<N-1, P<Rest...>> {};

template <template <typename...> class P, typename First, typename... Rest>
struct NthType<0, P<First, Rest...>> {
    using type = First;
};

template <int, int, typename> struct FindIndexOfIntHelper;

template <int N, int FindMe, template <int...> class Z, int... Rest>
struct FindIndexOfIntHelper<N, FindMe, Z<FindMe, Rest...>> : std::integral_constant<int, N> {};

template <int N, int FindMe, template <int...> class Z>
struct FindIndexOfIntHelper<N, FindMe, Z<>> : std::integral_constant<int, -1> {};  // Not found.

template <int N, int FindMe, template <int...> class Z, int First, int... Rest>
struct FindIndexOfIntHelper<N, FindMe, Z<First, Rest...>> : FindIndexOfIntHelper<N+1, FindMe, Z<Rest...>> {};

template <int FindMe, typename Pack>
using FindIndexOfInt = FindIndexOfIntHelper<0, FindMe, Pack>;

template <typename, typename, typename, typename> struct PermutePackHelper;

template <typename Pack, template <typename...> class P, typename... Accumulated, typename IndicesPack, template <int...> class Z>
struct PermutePackHelper<Pack, P<Accumulated...>, IndicesPack, Z<>> {
    using type = P<Accumulated...>;
};

template <typename Pack, template <typename...> class P, typename... Accumulated, typename IndicesPack, template <int...> class Z, int I, int... Is>
struct PermutePackHelper<Pack, P<Accumulated...>, IndicesPack, Z<I, Is...>> :
    PermutePackHelper<Pack, P<Accumulated..., typename NthType<FindIndexOfInt<I, IndicesPack>::value, Pack>::type>,
        IndicesPack, Z<Is...>> {};

template <typename, typename, typename> struct PermutePack;

template <template <typename...> class P, typename... Types, template <int...> class Z, int... Is, int... Js>
struct PermutePack<P<Types...>, Z<Is...>, Z<Js...>> : PermutePackHelper<P<Types...>, P<>, Z<Is...>, Z<Js...>> {};

// Now InsertTypes itself.
template <typename, typename, typename, int> struct InsertHelper;

template <typename T, template <typename...> class P, typename First, typename... Rest, typename... Accumulated>
struct InsertHelper<T, P<First, Rest...>, P<Accumulated...>, 0> {
    using type = P<Accumulated..., T, First, Rest...>;
};

template <typename T, template <typename...> class P, typename First, typename... Rest, typename... Accumulated, int N>
struct InsertHelper<T, P<First, Rest...>, P<Accumulated...>, N> : InsertHelper<T, P<Rest...>, P<Accumulated..., First>, N-1> {};

template <typename, typename, int> struct Insert;

template <typename T, template <typename...> class P, typename... Types, int N>
struct Insert<T, P<Types...>, N> : InsertHelper<T, P<Types...>, P<>, N> {};

template <typename, typename, typename> struct InsertTypesHelper;

template <typename Pack, template <typename...> class P, template <int...> class Z>
struct InsertTypesHelper<Pack, P<>, Z<>> {
    using type = Pack;
};

template <typename Pack, template <typename...> class P, typename First, typename... Rest, template <int...> class Z, int N, int... Ns>
struct InsertTypesHelper<Pack, P<First, Rest...>, Z<N, Ns...>> : InsertTypesHelper<typename Insert<First, Pack, N>::type, P<Rest...>, Z<Ns...>> {};

template <typename, typename, int...> struct InsertTypes;

template <typename Pack1, typename Pack2, typename Sequence, typename ReverseSequence>
using InsertTypesHelperAlias = InsertTypesHelper<Pack1, typename PermutePack<Pack2, Sequence, ReverseSequence>::type, ReverseSequence>;

template <int I, int J>
struct IntGreaterThan : std::conditional<(I > J), std::true_type, std::false_type>::type {};

template <int...> struct index_sequence {};

template <typename Pack, template <typename...> class P, typename... Types, int... Is>
struct InsertTypes<Pack, P<Types...>, Is...> : InsertTypesHelperAlias<Pack, P<Types...>, index_sequence<Is...>, typename SortIntSequence<index_sequence<Is...>, IntGreaterThan>::type> {};  // SortIntSequence<index_sequence<Is...>, IntGreaterThan>::type is the reverse sort of index_sequence<Is...>.

// Testing
template <typename...> struct Pack {};

int main() {
    std::cout << std::boolalpha << std::is_same<
        InsertTypes<Pack<int, double, char, long, int>, Pack<short, float, std::string>, 2,4,1>::type,
        Pack<int, std::string, double, short, char, long, float, int>
    >::value << std::endl;  // true 
}

【讨论】:

  • 如果把插入(第一次偏特化)写成template &lt;typename T, template &lt;typename...&gt; class P, typename... First, typename... Rest, typename... Accumulated&gt; struct InsertIntoPackOfPacksHelper&lt;T, P&lt;P&lt;First...&gt;, Rest...&gt;, P&lt;Accumulated...&gt;, 0&gt; { using type = P&lt;Accumulated..., P&lt;First..., T&gt;, Rest...&gt;; };,那么同样可以支持同索引的稳定插入。
  • 是的。我昨天做了进一步的更改,以便InsertTypes&lt;Pack&lt;int, double, char, long, int&gt;, Pack&lt;short, float, bool, std::string, int&gt;, 2,4,2,1,2&gt;::type 给出Pack&lt;int, std::string, double, int, bool, short, char, long, float, int&gt;,但我不确定结果是否应该是这样,因为它混淆了对同一索引的多次插入应该意味着什么。我的部分专业是struct InsertIntoPackOfPacksHelper&lt;T, P&lt;P&lt;First, Rest...&gt;, Others...&gt;, P&lt;Accumulated...&gt;, 0&gt; { using type = P&lt;Accumulated..., P&lt;T, First, Rest...&gt;, Others...&gt;; };
  • 我不太明白为什么您的部分专业化需要First。正如我所说,对于同一索引处的多个插入,我建议稳定性,即Pack&lt;int, string, double, short, int, char, long, float, int&gt;(提示:在示例中使用数组类型可能会提高可读性,例如InsertTypes&lt; Pack&lt;orig[0], orig[1], orig[2]&gt;, Pack&lt;insert[0], insert[1], insert[2]&gt;, 2,1,3 &gt; 和@987654330 @)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多