Index: boost/filesystem/v3/path.hpp =================================================================== --- boost/filesystem/v3/path.hpp (revision 72858) +++ boost/filesystem/v3/path.hpp (working copy) @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -565,12 +566,25 @@ inline bool operator==(const path& lhs, const path::string_type& rhs) { return lhs == rhs.c_str(); } inline bool operator==(const path::string_type& lhs, const path& rhs) { return rhs == lhs.c_str(); } inline bool operator==(const path::value_type* lhs, const path& rhs) { return rhs == lhs; } + + inline std::size_t hash_value(const path& x) + { + std::size_t seed = 0; + for(const path::value_type* it = x.c_str(); *it; ++it) + hash_combine(seed, *it == '/' ? L'\\' : *it); + return seed; + } # else // BOOST_POSIX_API inline bool operator==(const path& lhs, const path& rhs) { return lhs.native() == rhs.native(); } inline bool operator==(const path& lhs, const path::string_type& rhs) { return lhs.native() == rhs; } inline bool operator==(const path& lhs, const path::value_type* rhs) { return lhs.native() == rhs; } inline bool operator==(const path::string_type& lhs, const path& rhs) { return lhs == rhs.native(); } inline bool operator==(const path::value_type* lhs, const path& rhs) { return lhs == rhs.native(); } + + inline std::size_t hash_value(const path& x) + { + return hash_range(x.native().begin(), x.native().end()); + } # endif inline bool operator!=(const path& lhs, const path& rhs) { return !(lhs == rhs); } Index: libs/filesystem/v3/test/path_unit_test.cpp =================================================================== --- libs/filesystem/v3/test/path_unit_test.cpp (revision 72858) +++ libs/filesystem/v3/test/path_unit_test.cpp (working copy) @@ -43,6 +43,7 @@ #include #include #include // used constructor tests +#include #include #include @@ -399,9 +400,12 @@ { std::cout << "testing relationals..." << std::endl; + boost::hash hash; + # ifdef BOOST_WINDOWS_API // this is a critical use case to meet user expectations CHECK(path("c:\\abc") == path("c:/abc")); + CHECK(hash(path("c:\\abc")) == hash(path("c:/abc"))); # endif const path p("bar"); @@ -431,6 +435,9 @@ CHECK(L"baz" == p2); CHECK(wstring(L"baz") == p2); + CHECK(hash(p) == hash(p)); + CHECK(hash(p) != hash(p2)); // Not strictly required, but desirable + CHECK(!(p != p)); CHECK(p != p2); CHECK(p2 != p);