473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Create a template which declares STL iterator

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.

Feb 23 '06 #1
1 1613
ke*********@gmail.com wrote:
[..]
// 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
--
Please remove capital As from my address when replying by mail
Feb 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: NKOBAYE027 | last post by:
FIRST POST Hi All: I'm trying to write a simple specialization before moving on to something a bit more complex - always a good idea in my case, at least. :o) I'm trying to adapt the example...
10
by: rg | last post by:
Hi all, I was wondering if anyone had dealt with a similar problem. I need to use a template function as the parameter for a particular function (also template function). The program compiles...
1
by: darkstorm | last post by:
Please check this program...When I compiles it in VC.net, it gives the following error: =============== Common\Lib\PList.h(115): error C2440: '=' : cannot convert from 'ListNode *' to...
11
by: cyberdave | last post by:
Someone please help me! I have a template class like this: -------------------------------------------------- template<typename T> class List { public:
7
by: BigBrian | last post by:
I'm working a legecy system and have been tasked with upgrading the compiler from gcc 2.95.2 to 3.4.2. I have the following class which contains several std::map's. For simplicity, here I've...
2
by: booker | last post by:
the following codes can pass the compilation in VC6 but not in VC7.1.. is it a bug? #include <list> template<class type> class myclass { typedef myclass<type> mytype;
3
by: chriscorbell | last post by:
I'm curious about what appears to be a restriction on using an STL container inside a user-defined template, esp. using an iterator to such a container. It's not clear to me if this is a general...
2
by: Sherrie Laraurens | last post by:
Hi all, I'm trying to write a generic algorithm routine that will take begin and end iterators of a container, iterate through the range and perform a "calculation" of sorts. The trouble is...
8
by: Fab | last post by:
All, I need your help understanding why the following code does *NOT* compile with G++ (tested with gcc 3.x and 4.1.x): ---------------------------------------------------------------------...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.