views:

143

answers:

3

Are there any language lawyers in the house?

Should the following code compile?

include <set>

bool fn( const std::set<int>& rSet )
{
  if ( rSet.find( 42 ) != rSet.end() ) return true;
  return false;
}

On one of the platforms (Sun Workshop) this does not compile. It reports that the find function returned an iterator and the end function that returned a const_iterator and that it does not have a valid comparison operator between those types.

The following does compile:

include <set>

bool fn( std::set<int>& rSet )
{
  if ( rSet.find( 42 ) != rSet.end() ) return true;
  return false;
}
+2  A: 

I can't duplicate this exact behavior on my platform, but I have run into similar problems in the past with STL maps. I found that I needed to explicitly assign the result of find() to a declared variable, and then compare that variable to the result of end(). It may be worth a shot.

zweiterlinde
+9  A: 

It should compile. Set includes 2 find() functions and 2 end() functions (const and non-const versions). It sort of sounds like Sun's STL is broken somehow. Since you are passing in a const reference, the compiler should be able to select the correct find() and end() functions.

Brian Neal
+3  A: 

It's been a couple of years since I used a Sun C++ compiler, but at that time it had two STL versions. One was a legacy version, which wasn't anywhere near complete or correct, but which they kept to compile older programs, and one was stlport. Check to make sure you're using a correct STL version.

David Thornley