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

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

I have declared this STL multiset:

multiset playingNotes;

and my comparator is:



        
4条回答
  •  春和景丽
    2021-01-23 15:08

    Solution with Boost.MultiIndex:

    Live Coliru Demo

    #include 
    #include 
    #include 
    #include 
    
    using namespace boost::multi_index;
    
    struct IMidiMsgExt
    {
      int mTick;
      int mTone;
    };
    
    using MidiSet=multi_index_container<
      IMidiMsgExt,
      indexed_by<
        ordered_unique>,
        hashed_non_unique>
      >
    >;
    
    #include 
    
    int main()
    {
      MidiSet m={{0,100},{2,60},{3,150},{5,60},{1,200},{4,90}};
    
      std::cout<<"before erasing:\n";
      for(const auto& msg:m)std::cout<<"["<().erase(60);
    
      std::cout<<"after erasing:\n";
      for(const auto& msg:m)std::cout<<"["<

    Output

    before erasing:
    [0,100][1,200][2,60][3,150][4,90][5,60]
    after erasing:
    [0,100][1,200][3,150][4,90]
    

提交回复
热议问题