$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r73827 - in trunk: boost/filesystem/v3 libs/filesystem/v3/test
From: dnljms_at_[hidden]
Date: 2011-08-16 18:15:56
Author: danieljames
Date: 2011-08-16 18:15:55 EDT (Tue, 16 Aug 2011)
New Revision: 73827
URL: http://svn.boost.org/trac/boost/changeset/73827
Log:
Filesystem: add hash_value.
Text files modified: 
   trunk/boost/filesystem/v3/path.hpp               |    14 ++++++++++++++                          
   trunk/libs/filesystem/v3/test/path_unit_test.cpp |     7 +++++++                                 
   2 files changed, 21 insertions(+), 0 deletions(-)
Modified: trunk/boost/filesystem/v3/path.hpp
==============================================================================
--- trunk/boost/filesystem/v3/path.hpp	(original)
+++ trunk/boost/filesystem/v3/path.hpp	2011-08-16 18:15:55 EDT (Tue, 16 Aug 2011)
@@ -29,6 +29,7 @@
 #include <boost/shared_ptr.hpp>
 #include <boost/io/detail/quoted_manip.hpp>
 #include <boost/static_assert.hpp>
+#include <boost/functional/hash_fwd.hpp>
 #include <string>
 #include <iterator>
 #include <cstring>
@@ -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); }
Modified: trunk/libs/filesystem/v3/test/path_unit_test.cpp
==============================================================================
--- trunk/libs/filesystem/v3/test/path_unit_test.cpp	(original)
+++ trunk/libs/filesystem/v3/test/path_unit_test.cpp	2011-08-16 18:15:55 EDT (Tue, 16 Aug 2011)
@@ -43,6 +43,7 @@
 #include <boost/detail/lightweight_test.hpp>
 #include <boost/detail/lightweight_main.hpp>
 #include <boost/smart_ptr.hpp>  // used constructor tests
+#include <boost/functional/hash.hpp>
 
 #include <iostream>
 #include <iomanip>
@@ -399,9 +400,12 @@
   {
     std::cout << "testing relationals..." << std::endl;
 
+    boost::hash<path> 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);