/*
#include <iostream>
#include <string>
#include <vector>
#include <list>
using namespace std;
template <typename I, typename T>
I find(I b, I e, const T &v) {
while (b != e && *b != v) {
b++;
return b;
}
}
int main() {
vector<int> vi = {0, 2, 4, 6, 8, 10};
list<string> ls = { "Hello", "World", "!" };
auto iter = find(vi.begin(), vi.end(), 6);
//vector<int> iter = find(vi.begin(), vi.end(), 6);
if (iter == vi.end())
std::cout << "find 6 at position" << std::endl;
else
std::cout << "find 6 at position" << iter - vi.begin() << std::endl;
auto iter1 = find(ls.begin(), ls.end(), "mom");
//list<string> iter1 = find(ls.begin(), ls.end(), "mom");
if (iter == ls.end()) {
std::cout << "can't find mom" << std::endl;
}
else
std::cout << "found mom" << std::endl;
return 0;
}
*/
#include <iostream>
#include <vector>
#include <list>
using namespace std;
template <typename I, typename T>
I find(I beg, I end, T val)
{
auto iter = beg;
for (; iter != end; ++iter)
if (*iter == val)
break;
return iter;
}
int main()
{
vector<int> iv = {1, 2, 3, 4, 5};
list<string> slst = {"dog", "cat", "rat"};
auto p1 = find(iv.begin(), iv.end(), 4);
if (p1 != iv.end())
cout << *p1 << endl;
auto p2 = find(slst.begin(), slst.end(), "rat");
if (p2 != slst.end())
cout << *p2 << endl;
return 0;
}