本文介绍了将非特化模板作为模板参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以做类似的事情吗
template<class Key, class Data, class Compare = less<Key>, template<typename T> class Allocator<T> = allocator<T> >
class mymap {
typedef map<Key,Data,Compare,Allocator<pair<const Key, Data> > > storageMap;
typedef vector<Data,Allocator<Data> > storageVector;
}
因此模板被传递给未特化的类并稍后实例化.
So template is passed to the class unspecialiazed and instantiated later.
推荐答案
是的,这是一个最小的可编译示例:
Yes, here's a minimal compileable example:
#include <map>
#include <vector>
using namespace std;
template <
class Key,
class Data,
class Compare = less<Key>,
template <typename T> class Allocator = allocator
>
class mymap
{
public:
typedef map<Key,Data,Compare,Allocator<pair<const Key, Data> > > storageMap;
typedef vector<Data,Allocator<Data> > storageVector;
};
int main()
{
mymap<int,long>::storageMap m;
mymap<int,long>::storageVector v;
return 0;
}
这篇关于将非特化模板作为模板参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!