Is there another way to increment the iterator while still keeping the const of beg? This works fine for vectors but I guess the compiler is freaking out when it comes to list iterators.
#include<iostream>
using std::cout;
#include<list>
using std::list;
#include<vector>
using std::vector;
#include<string>
using std::string;
template <typename ITER, typename V>
ITER find(const ITER &beg, const ITER &end, const V &sought)
{
while (beg != end)
{
if (*beg == sought)
return beg;
return (beg + 1, end, sought);
}
return end;
}
int main()
{
list<string> li { "Hello", "World"};
auto res = find(li.begin(), li.end(), "World");
cout << *res;
}
Thanks for the examples. The 2nd one doesn't seem to work though but I get the idea, and the 3rd just flies over my head, gonna have to take a look at that closely, thanks again.