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;
}
-
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 ofend()
. It may be worth a shot. -
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.
-
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.
0 comments:
Post a Comment