How can I set two kind of comparator (one for insert, one for find) on this multiset?

后端 未结 4 1753
忘了有多久
忘了有多久 2021-01-23 14:48

I have declared this STL multiset:

multiset playingNotes;

and my comparator is:



        
4条回答
  •  没有蜡笔的小新
    2021-01-23 15:00

    I'd agree with Mohamad Elghawi's answer. But it is incomplete.

    Your actual code will use a find_if, just like this:

    const auto it = find_if(cbegin(playingNotes), cend(playingNotes), [value = int{60}](const auto& i){return i.mNote == value;});
    
    if(it != cend(playingNotes)) {
        playingNotes.erase(it);
    }
    

    This will remove the IMidiMsgExt with the lowest mTick value which has an mNote of 60 (or whatever value was initialized to.) If there are multiple IMidiMsgExts in playingNotes that tie for the lowest, the IMidiMsgExt that has been in playingNotes the longest will be removed.

    You're explanation of the problem was a little sparse, so I've created and solved a Minimal, Complete, Verifiable Example here: http://ideone.com/oFQ4rS

提交回复
热议问题