STL map

M

maverick

Hello

I am trying to write a wrapper for the MFC Cmap


I am trying to write the equivalent of CMap::Lookup ( KEY key , VALUE
&value)


template < class KEY , class VALUE >
class CMap
{

...

...

CMap::Lookup ( KEY key , VALUE &value)
{

typename CMap<KEY , VALUE>::iterarator iter ;

// Need to initialize iterator to a default value , like NULL or 0


iter.find(key);
// if(iter!= DEFAULT VALUE)
{
value = *iter ;
return TRUE ;
}

return FALSE





}

private :
map<KEY , VALUE> m_map ;

} ;



Now I want to set a default value for the iterator , like a NULL or a 0
, so that using "find" I can check the result and set the value .


I would like to know a good place for STL Documentation


Thanks
 
D

Daniel T.

maverick said:
Now I want to set a default value for the iterator , like a NULL or a 0
, so that using "find" I can check the result and set the value .

In standard C++, the iterator used for "not found" is the "end()" of the
container.

map< KEY, VALUE >::iterator it = m_map.find( key );
if ( it != m_map.end() ) {
value = *it;
return true;
}
else {
return false;
}
I would like to know a good place for STL Documentation

My two favorites are:

http://www.sgi.com/tech/stl/
http://www.dinkumware.com/manuals/
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top