C++ Custom Comparators for container

useful to sort automatically as you insert elements

Custome comparator

struct MyData
{
MyData(const std::string& str, int v) : key(str), value(v) {}
std::string key;
int value;
};
struct Compare
{
bool operator()(const MyData &lhs, const MyData &rhs) const
{
return lhs.key < rhs.key;
}
};
int main()
{
std::set<MyData, Compare> myset;
myset.insert(MyData("Bob", 1));
}