M
mos
Hi!
There are two function almost the same:
function removelist()
{
for(list<a*>::iterator it = m_list.begin(); it != m_list.end(); )
{
a* p = *it;
if (!p->IsValid())
{
delete p;
it = m_list.erase(it)
}
else
++it;
}
}
function removemap()
{
for(map<int,a*>::iterator it = m_map.begin(); it != m_map.end(); )
{
a* p = it->second;
if (!p->IsValid())
{
delete p;
it = m_map.erase(it)
}
else
++it;
}
}
how can I use templete to simply the code like
template<class ...>
function removeT(...)
{
...
}
the problem is the list: p = *it and map: p = it->second
then
function removelist()
{
removeT(m_list)
}
function removemap()
{
removeT(m_map)
}
There are two function almost the same:
function removelist()
{
for(list<a*>::iterator it = m_list.begin(); it != m_list.end(); )
{
a* p = *it;
if (!p->IsValid())
{
delete p;
it = m_list.erase(it)
}
else
++it;
}
}
function removemap()
{
for(map<int,a*>::iterator it = m_map.begin(); it != m_map.end(); )
{
a* p = it->second;
if (!p->IsValid())
{
delete p;
it = m_map.erase(it)
}
else
++it;
}
}
how can I use templete to simply the code like
template<class ...>
function removeT(...)
{
...
}
the problem is the list: p = *it and map: p = it->second
then
function removelist()
{
removeT(m_list)
}
function removemap()
{
removeT(m_map)
}