hi all,
if you look at the code below you will see that i am trying to get a template function to return an iterator based on the type type of one of its parameters,
i cant seem to get it to work
i dont want to have to pass an iterator to the function i want to get it from the container that is passed
i am using dev-c++ to compile
can anyone please tell me if this is possible?
template <class container, class iter, class valtype>
iter findInContainer(container c, valType vt)
{
typedef typename container::iterator c_iter;
c_iter iter = c.begin();
while (iter != c.end())
{
if (*iter == vt)
{
return iter;
} else
{
++iter;
}
}
return c.end();
}
int main()
{
vector<int> intVec;
intVec.push_back(1);
intVec.push_back(2);
intVec.push_back(3);
findInContainer(intVec, 4);
//should return intVec.end()
list<int> intlist;
intlist.push_back(1);
intlist.push_back(2);
intlist.push_back(3);
findInContainer(intlist, 2);
//should return iterator for intList[1]
return 1;
}