C++11, boost::filesystem::path, no std::hash specialization
Hi there, I cannot use boost::filesystem::path with an e.g. unordered_set because std::hash seems not to be specialized for this type. Is this intended? Should I file a bug? Or am I completely misguided? I use 1.52 libraries with -DBOOST_FILESYSTEM_NO_DEPRECATED. I searched the bug database but did not find anything relevant (other than this https://svn.boost.org/trac/boost/ticket/5650 ticket). Thanks in advance, -Benjamin
Hi Benjamin,
On Sun, Dec 2, 2012 at 1:57 PM, Benjamin Kircher wrote: I cannot use boost::filesystem::path with an e.g. unordered_set because
std::hash seems not to be specialized for this type. Is this intended?
Should I file a bug? Or am I completely misguided? I can't comment on whether filesystem::path should be extended to work with
boost hash, but I wanted to point out that you could supply your own
hashing object (not boost hash, but using hash_combine) without needing to
do anything in the boost namespace. That would work now and in the
possible future where filesystem::path supports boost::hash.
See <
http://www.boost.org/doc/libs/1_52_0/doc/html/unordered/hash_equality.html>.
The patch Daniel James attached to the ticket you referenced is probably a
good starting point for implementing something like that.
HTH,
Nate
Hi Nate, On Sun, Dec 2, 2012 at 11:46 PM, Nathan Crookston < nathan.crookston@gmail.com> wrote:
Hi Benjamin,
On Sun, Dec 2, 2012 at 1:57 PM, Benjamin Kircher < benjamin.kircher@gmail.com> wrote:
I cannot use boost::filesystem::path with an e.g. unordered_set because std::hash seems not to be specialized for this type. Is this intended? Should I file a bug? Or am I completely misguided?
I can't comment on whether filesystem::path should be extended to work with boost hash, but I wanted to point out that you could supply your own hashing object (not boost hash, but using hash_combine) without needing to do anything in the boost namespace. That would work now and in the possible future where filesystem::path supports boost::hash.
See < http://www.boost.org/doc/libs/1_52_0/doc/html/unordered/hash_equality.html>. The patch Daniel James attached to the ticket you referenced is probably a good starting point for implementing something like that.
thanks for the kind reply.
I found out that boost::filesystem already provides a function
hash_value(const path&) which does exactly what you pointed out (it uses
hash_combine/hash_range internally).
I was then able to provide my own specialization of std::hash with:
#include
participants (2)
-
Benjamin Kircher
-
Nathan Crookston