STL set can have customized comparator. It can be implemented in several ways, such as define an operator(), use decltype on lambda, etc. I was trying to use a static method of a class and encountered a weird crash. The crash can be demonstrated by the following code
#include <string>
#include <set>
struct Foo {
static bool Compare(std::string const& s1, std::string const& s2)
{
return s1 < s2;
}
};
std::set<std::string, decltype(&Foo::Compare)> S;
int main()
{
S.insert("hello");
S.insert("world");
return 0;
}
The crash happened on the second insert. Thank you.