[boost bimap]- question on use of optional sorting predicate for set_of declarations
I have a question with sorting of sets in the bimap framework. I have a bimap declared thus: //Boost Bimap requires this predicate struct setup struct AreDecalIDsInCorrectRenderOrderStruct { bool operator() (const short nDecalID1, const short nDecalID2) const { //Do comparison } }; typedef boost::bimap<boost::bimaps::unordered_multiset_of<int>, boost::bimaps::set_of<short, AreDecalIDsInCorrectRenderOrderStruct>> intMultisetShortSetBimap; intMultisetShortSetBimap m_mStructureIDToLinkedDecalID; The problem is this isn't working as I expected. I'm expecting that when I insert elements using: m_mStructureIDToLinkedDecalID.insert(intMultisetShortSetBimap ::value_type(nStructureID, nDecalID)); and then later retrieve them using: pair<intMultisetShortSetBimap ::left_const_iterator, intMultisetShortSetBimap ::left_const_iterator> equalRange = m_mStructureIDToLinkedDecalID.left.equal_range(nStructureID); that the retrieved elements with equal range would be sorted according to the predicate I used. But they aren't. Instead their order is dependent on the order they were inserted. I've verified that my predicate is being called on insertions. Am I misunderstanding the purpose of passing a sorting predicate to a set_of declaration? If so, what does the sorting actually do and is there a way to get boost::bimap to do what I want? Thanks for any help. -Curtis _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the originator of the message. This footer also confirms that this e-mail message has been scanned for the presence of computer viruses. Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of Indra Systems, Inc.
Hello Curtis, On Fri, Nov 27, 2009 at 1:41 PM, Curtis Himel <chimel@indra-systems.com> wrote:
I have a question with sorting of sets in the bimap framework. I have a bimap declared thus:
//Boost Bimap requires this predicate struct setup struct AreDecalIDsInCorrectRenderOrderStruct { bool operator() (const short nDecalID1, const short nDecalID2) const { //Do comparison } };
typedef boost::bimap<boost::bimaps::unordered_multiset_of<int>, boost::bimaps::set_of<short, AreDecalIDsInCorrectRenderOrderStruct>> intMultisetShortSetBimap;
intMultisetShortSetBimap m_mStructureIDToLinkedDecalID;
Til this point, everything is ok and you have customized the right set of the bimap with your custom sorting predicate.
The problem is this isn't working as I expected. I'm expecting that when I insert elements using:
m_mStructureIDToLinkedDecalID.insert(intMultisetShortSetBimap ::value_type(nStructureID, nDecalID)); and then later retrieve them using:
pair<intMultisetShortSetBimap ::left_const_iterator, intMultisetShortSetBimap ::left_const_iterator> equalRange = m_mStructureIDToLinkedDecalID.left.equal_range(nStructureID);
that the retrieved elements with equal range would be sorted according to the predicate I used. But they aren't. Instead their order is dependent on the order they were inserted.
The thing is that you are using the left view of the bimap, and not the one you have customized. Try using the right view map, it should work as you expect. Best regards Matias
participants (2)
-
Curtis Himel
-
Matias Capeletto