Skip to content

Instantly share code, notes, and snippets.

@pk13610
Created August 22, 2018 14:29
Show Gist options
  • Save pk13610/0e1262003488f78ca557aa68cc82e8e2 to your computer and use it in GitHub Desktop.
Save pk13610/0e1262003488f78ca557aa68cc82e8e2 to your computer and use it in GitHub Desktop.
#include <set>
#include <iostream>
struct MyStruct
{
int kk;
bool operator<(const MyStruct & right) const
{
return kk > right.kk;
}
};
struct MyStructCmp
{
bool operator()(const MyStruct& left, const MyStruct& right)
{
return left.kk > right.kk;
}
};
int main(int argc, char* argv[])
{
//std::set<MyStruct> ss;
std::set<MyStruct, MyStructCmp> ss;
for (int i = 0; i < 100; i++)
{
MyStruct ms;
ms.kk = i;
ss.insert(ms);
}
for (auto it=ss.begin(); it != ss.end(); ++it)
{
std::cout << it->kk << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment