Multiset in C++
1 min readJul 3, 2020
What is multiset<int, greater<int>> ms;
From [1]
multiset<int, greater<int> > ms1;
This says that ms1
is a std::multiset
, storing int
, and using a comparison functor of the type std::greater<int>
. You've left out constructor arguments, so the instance of the functor is a default constructed one, exactly as if you had passed std::greater<int>{}
, like this:
multiset<int, greater<int> > ms1(greater<int>{});#include <iostream>
#include <set>
using namespace std;int
main ()
{
multiset < int, greater<int>>ms1;
ms1.insert(10);
ms1.insert(20);
for(auto& m: ms1)cout<<m<<endl;
multiset < int, greater<int>>ms2 (greater <int> {});
ms2.insert(10);
ms2.insert(20);
for(auto& m: ms2)cout<<m<<endl;
return 0;
}