473,811 Members | 3,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create a template which declares STL iterator

Hi,
I have the following code which comples:

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

vector<A*>::ite rator 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 1625
ke*********@gma il.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
1776
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 from Stroustrup, 3rd ed., The C++ Programming Language p. 344 I'm using MSDev 6.0 in case that's an issue. Here's the source...
10
1793
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 into an object file but then at the final stage it says that it can't find template function. The platform is WindowsXP Pro, MSCV++ ..Net. More specifically what I want to do is write an atl algorithm that will also
1
2128
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 'List<T>::ListNode *' with Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast project\Source\Levelmgr.cpp(198) : while compiling
11
3611
by: cyberdave | last post by:
Someone please help me! I have a template class like this: -------------------------------------------------- template<typename T> class List { public:
7
1612
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 created two a map from int to int and int to double. The keys are "schronized", ie all items are added in the set of maps by way of the add() member function. There is a template function that basically handles the error of the items not being in...
2
1279
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
2401
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 template/language restriction, and STL iterator limitation, or if I'm just going about it wrong. I'm declaring a template which uses a std::map to store references to the template type, e.g. template template <typename T>
2
2150
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 that the algorithm will behave differently for the two different types. I've considered calling the algorithm foo_A and foo_B, but I don't like that approach because it will blow out in naming complexity down the track.
8
1887
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): --------------------------------------------------------------------- template<class T> class myvector { // Just a simplification of std::vector class iterator { T a; iterator &operator++(); };
0
9724
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10127
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7665
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.