我想写一个函数,它可以接受任何标准容器(列表,堆栈,向量等)作为参数。我也希望知道容器内的类型。这是我尝试过的。带有模板化参数的C++函数模板
#include<iostream>
#include<list>
#include<vector>
template<class data_type, template<class> class container_type>
void type(container_type<data_type>& _container){
std::cout<<typeid(container_type).name()<<std::endl;
}
int main(){
std::list<int> list_t;
std::vector<int> vector_t;
type(list_t);
type(vector_t);
}
一旦此功能内的类型的container_type
总是_Container_base_aux_alloc_empty
其中(我认为)是一个基类的标准容器。
这是怎么回事?
我该如何让这个函数返回正确的类型?