本文介绍了矢量的对与通用矢量和对类型,模板模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想传递一个对的向量到一个函数。实际的向量实现以及对的类型应该是模板参数。



我想到这样的东西:

 的 code>作为 pair.first 和 pair.second 的类型。

解决方案

您可以使用:

  template< X,
typename Y,
template< typename,typename> class Pair,
template< typename ...> class Vector>
void fun(Vector< Pair< X,Y>> vec)
{
// ...
}
/ pre>

I'd like to pass a vector of pairs to a function. The actual vector implementation as well as the types of the pair should be a template parameter.

I thought of something like this:

template<uint8_t t_k,
        typename t_bv,
        typename t_rank,
        template <template <template<typename t_x,
                                     typename t_y> class std::pair>
                  typename t_vector>> typename t_vector>

The first 3 are other template parameters. The last template parameter should allow to pass a vector (std or stxxl:vector) of std::pair with either uint32_t or uint64_t as type of the pair.first and pair.second.

解决方案

You can use this:

template<typename X,
         typename Y,
         template<typename, typename> class Pair,
         template<typename...> class Vector>
void fun(Vector<Pair<X, Y>> vec)
{
     //...
}

这篇关于矢量的对与通用矢量和对类型,模板模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:46
查看更多