Create a template which declares STL iterator

K

ken.carlino

Hi,
I have the following code which comples:

bool contains(vector<A*>& cgl, A* cg) {

vector<A*>::iterator iter = find_if ( cgl.begin(), cgl.end(), bind(
equal_to<A*>(), _1, cg ));

return (iter != cgl.end());
}

anb how I want to create a template of the above code:
template<class T1, class T2>
bool contains(T1& cgl, T2 cg) {
// this is line 189 of Utils.h
T1::iterator iter = find_if ( cgl.begin(), cgl.end(),
boost::lambda::bind( equal_to<T2>(), boost::lambda::_1, cg ));

return (iter != cgl.end());
}


but I have the compile error:
.../Utils.h: In function 'bool contains(T1&, T2)':
.../Utils.h:189: error: expected `;' before 'iter'
.../Utils.h:191: error: 'iter' was not declared in this scope

Thanks for any idea.
 
V

Victor Bazarov

[..]
// this is line 189 of Utils.h
T1::iterator iter = find_if ( cgl.begin(), cgl.end(),

You probably want to make it

typename T1::iterator iter = ...
boost::lambda::bind( equal_to<T2>(), boost::lambda::_1, cg ));

return (iter != cgl.end());
}


but I have the compile error:
../Utils.h: In function 'bool contains(T1&, T2)':
../Utils.h:189: error: expected `;' before 'iter'
../Utils.h:191: error: 'iter' was not declared in this scope

Thanks for any idea.


V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top