Sign in to follow this  
gimp

if ::iterator == 0 causes error:

Recommended Posts

I have a handle class. The handle class hold an iterator in to a map.
typename typedef std::map<std::string, std::pair<ResourceType*, size_t> >::iterator ResourceItr;

ResourceItr	m_Resource;
On construction my code sets the Resource handle to 0. Later I test for the validity of the handle :
template <class ResourceType, typename IOType>
inline bool CHandle<ResourceType, IOType>::IsNull(void) const
{
	return (m_Resource == 0); <<<<<<<<<<<<<<<<<<<<<
}
For some reason since upgrading to VS 2005 this test of wether a iterator is null is no longer valid. Can anyone think of why this may no longer be valid?

Share this post


Link to post
Share on other sites
hmmmm... I guess I could just add a bool to the hanlde class to track it that way. I can't use .end as the handle is hel by object that exist before the container exists and needs to be assigned later.

I'm quite suprised that I shouln't do that. I wonder where I picked that up from...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you want to test if the ResourceType* is NULL right?

well the map stores its data as a std::pair,
so to test for ResourceType*==0 you would have to do:

inline bool CHandle::IsNull(void) const
{
return (m_Resource->second.first == 0); <<<<
}

i have no idea what the overloaded == operator does in the map::iterator though... but it should never have worked...

Share this post


Link to post
Share on other sites
If the iterator is actually just a pointer (which is quite possible) then it could evaluate correctly. I wonder whether the newer STL libraries have debug behaviour which detects misuse. Just a thought, no factual basis.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this