template< class In, class T> In find( In first, In last, const T& v) {
while ( first != last && *first != v)
++first;
return first;
}
template<class In> struct Iseq : public std::pair< In, In > {
Iseq(In i1, In i2) : std::pair< In, In >(i1, i2) { }
};
template<class In, class T> In find( Iseq<In>& r, const T& v) {
return find(r.first, r.second, v);
}
template< class C>
Iseq<typename C::iterator> my_iseq(C& c) {
return Iseq<typename C::iterator>(c.begin(), c.end() );
}
void f(std::list<std::string>& ls) {
std::list<std::string>::iterator q = find(my_iseq(ls), "extension");
}
my_iseq(ls) inside f() on line 21 results in find() on line 11 being called. At its return statement on line 12, in order to resolve r.first and r.second, my_iseq(C& c) on line 16 is called. On line 17, Iseq's ctor of line 8 is called. Now that r.first and r.second are completely resolved, the return statement on line 12 results in find() on line 1 being called.