C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: const map templated 'find'

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
shaun
Guest





PostPosted: Fri Jan 27, 2006 4:28 pm    Post subject: Re: const map templated 'find' Reply with quote




Quote:
template <class S, class T
T constFind(const map< S, T > & theMap, const S & theKey, const T &
errVal){
map< S, T>::const_iterator ppair(theMap.find(theKey));
return (ppair not_eq theMap.end())?(ppair->second):errVal;
}

and then in the body of the code just have

theValue = constFind(myMap, aKey, anErrVal);


on one of my compilers (gcc 3.2.3) this appears to compile (havent tried
running it), on the other (gcc 4.0.0) it doesn't.


Keep 'ppair' an iterator. Let's make it work with that.

V

Indeed the compilers gave me a helpful clue, that really what I meant
was:

typename map< S, T>::const_iterator ppair(theMap.find(theKey));

and suddenly all is well.

cheers

shaun

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.