Код: Выделить всё
#include
#include
#include
#include
struct Storage
{
struct Hash
{
std::size_t operator()(const Storage& storage) const noexcept
{
return std::hash{}(storage.key);
}
};
std::string key;
// One more fat fields...
};
bool
operator==(const Storage& lhs, const Storage& rhs) noexcept
{
return lhs.key == rhs.key;
}
bool
operator==(const Storage& lhs, const std::string& rhs) noexcept
{
return lhs.key == rhs;
}
int
main()
{
auto uset = std::unordered_set
{
{ .key="42" }
};
// Variant #1 - works
auto it = uset.find({ .key="42" /* and init other fields */ });
// Variant #2 - doesn't compiles :(
auto it = uset.find(std::string("42"));
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... rdered-set
Мобильная версия