I’ve got some code which involves iterating through a std::hash_set something like this:
typedef std::hash_set< VEdge, VEdge > MyHashSet;
MyHashSet hs;
for( int i=0; i < numFaces; ++i )
{
VEdge myEdge( someValue, someOtherValue );
MyHashSet::iterator it = hs.find(myEdge);
if ( it->face[0] == -1 )
it->face[0] = i; // Error: "Read-only variable is not assignable"
}
I’ve changed the code around to simplify it, but you can sort of see what it’s doing. VEdge is defined in a struct that has int face[2] as one of its members. The problem I am having is that Clang tells me that it->face[0] is read-only, even though this same code works on MSVC (or so I’m told). Is there something about Clang that means I have to define the face variable as writable somehow?
The
hash_setclass is non-standard. Microsoft’s version allows you to modify the contents of the object viaiterator, but SGI’s version, which is the version I’ve guessing you’re using with Clang, hasiteratorandconst_iteratoras the same type, meaning you can’t modify the contents of the container via iterators.That’s just as well, since the positions of the objects in the container are determined by their hashes, and their hashes are determined by their values. Changing their values would requiring changing their positions, but the hash set cannot detect that you’re changing their values, so the container would be inconsistent. (Maybe the members you’re modifying don’t really affect the hash, but there’s no way for
hash_setto know that. Microsoft’s version probably leaves behavior undefined if you modify the contents, whereas SGI prohibits the operation entirely.)