Initializing multiset with custom comparison function in C++

前端 未结 4 1372
独厮守ぢ
独厮守ぢ 2021-02-04 14:50

Consider following comparison function:

bool compare(std::shared_ptr &lhs, std::shared_ptr &rhs){
   return lhs->val         


        
4条回答
  •  天涯浪人
    2021-02-04 15:11

    In order to access your elements, you need to provide function for strict weak ordering for your type.

    std::multiset have the following constructor:

     explicit multiset (const key_compare& comp = key_compare(),
                   const allocator_type& alloc = allocator_type());
    

    As you can see, you can do this by passing comp function pointer (or function object) to the constructor.


提交回复
热议问题