#include <set>
#include <string>
#include <string_view>
using namespace std;
int main()
{
string_view key = "hello";
set<string> coll1;
coll1.find(key); // error
set<string, less<>> coll2;
coll2.find(key); // ok since C++14
}
那么,它应该是一个规则:
总是喜欢 set<T, less<>>
到 set<T>
C++14 起?
最佳答案
找到反例很简单:
#include <set>
#include <string>
using namespace std;
struct converts_to_string {
operator string() const { return ""; }
};
int main()
{
converts_to_string key;
set<string> coll1;
coll1.find(key); // OK
set<string, less<>> coll2;
coll2.find(key); // error
}
关于c++ - 自 C++14 以来,总是更喜欢 set<T, less<>> 到 set<T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41094116/