Input sequence: code annotation

Hi, folks,

Looking at the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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.

Is my above annotation correct?
Last edited on
Robertlzw wrote:
in order to resolve r.first and r.second, my_iseq(C& c) on line 16 is called.


my_iseq() is called because you explicitly call it on line 21; this does not happen because of ADL as your write-up suggests.

Why define find() on line 1 when <algorithm> provides the very same function?
Topic archived. No new replies allowed.