boost::filesystem::path hashen
-
Hoi,
was ist hier verkehrt?
struct PathHasher { inline std::size_t operator()(boost::filesystem::path const& path) const noexcept { return std::hash<decltype(path.string())>()(path.string()); } };std::hash meckert immer, dass es dafür nicht spezialisiert ist.
Ersetze ich decltype(...) durch std::string dann funktioniert es.
Habe mit std::removew_const und mit std::remove_reference herumgespielt und es passt immer noch nicht.Was wäre dire korrekte Lösung?
Danke und Grüße,
Ethon
-
Wenn decltype involviert ist, sollte man sich sowieso angewöhnen immer
std::decay<decltype(...)>::typezu verwenden.
-
Ah, jetzt funktioniert's ... danke.
Komisch dass ich mit remove_const und remove_reference string const& nicht zu string bekommen habe ... najo, was solls.
-
Kleine Nebenfrage: Wo steht im Standard, dass der Ctor oder der Funktionsoperator noexcept sein müssen? Muss bei dir dann das
noexceptnicht eher bedingt sein?Edit:
N3337 §20.8.12/1 schrieb:
[...] the
instantiation hash<Key> shall: [...] satisfy the requirement that the expression h(k), where h is an object of type hash<Key> and k is an
object of type Key, shall not throw an exception unless hash<Key> is a user-defined specialization that
depends on at least one user-defined type.
-
Sone schrieb:
Kleine Nebenfrage: Wo steht im Standard, dass der Ctor oder der Funktionsoperator noexcept sein müssen? Muss bei dir dann das
noexceptnicht eher bedingt sein?Edit:
N3337 §20.8.12/1 schrieb:
[...] the
instantiation hash<Key> shall: [...] satisfy the requirement that the expression h(k), where h is an object of type hash<Key> and k is an
object of type Key, shall not throw an exception unless hash<Key> is a user-defined specialization that
depends on at least one user-defined type.Najo, ich hab einfach den Body aus der libstdc++ Implementierung von std::hash rauskopiert und editiert, garnicht darüber nachgedacht.
Aber da sowieso niemals eine Exception beim Hashen von string fliegen könnte ... relativ egal ob's dasteht oder nicht.
