以下如何写个函数模板 的函数?
typedef multimap<int,int> ClientIndex;
typedef multimap<int,string> FormIndex;
void __fastcall FindValue( ClientIndex* map,int key,int value)
{
ClientIndex::size_type count = map->count(key);
if(count > 0)
{
ClientIndex::iterator iter = map->find(key);
for(ClientIndex::size_type cnt = 0; cnt!= count; ++cnt,++iter)
{
if(iter->second == value)
{
//如果在multimap中找到value相同的就退出
return;
}
}
//如果没有找到对应的value,就插入到multimap中
}
//没有找到对应的key 值,或者value值就插入到multimap中
map->insert(make_pair(key,value));
}
void __fastcall FindValue(FormIndex* map,int key ,const string &value)
{
FormIndex::size_type count = map->count(key);
if(count > 0)
{
FormIndex::iterator iter = map->find(key);
for(FormIndex::size_type cnt = 0; cnt!= count; ++cnt,++iter)
{
string tempvalue = iter->second;
if(tempvalue == value)
{
//如果在multimap中找到value相同的就退出
return;
}
}
//如果没有找到对应的value,就插入到multimap中
}
//没有找到对应的key 值,或者value值就插入到multimap中
map->insert(make_pair(key,value));
}
template <class T,class I>
void __fastcall FindValue(T* map,int key ,I value)
{
//这个该如何实现
}