Ticket #5650: filesystem.patch

File filesystem.patch, 2.8 KB (added by Daniel James, 11 years ago)
  • boost/filesystem/v3/path.hpp

     
    2929#include <boost/shared_ptr.hpp>
    3030#include <boost/io/detail/quoted_manip.hpp>
    3131#include <boost/static_assert.hpp>
     32#include <boost/functional/hash_fwd.hpp>
    3233#include <string>
    3334#include <iterator>
    3435#include <cstring>
     
    565566  inline bool operator==(const path& lhs, const path::string_type& rhs) { return lhs == rhs.c_str(); }
    566567  inline bool operator==(const path::string_type& lhs, const path& rhs) { return rhs == lhs.c_str(); }
    567568  inline bool operator==(const path::value_type* lhs, const path& rhs)  { return rhs == lhs; }
     569
     570  inline std::size_t hash_value(const path& x)
     571  {
     572    std::size_t seed = 0;
     573    for(const path::value_type* it = x.c_str(); *it; ++it)
     574      hash_combine(seed, *it == '/' ? L'\\' : *it);
     575    return seed;
     576  }
    568577# else   // BOOST_POSIX_API
    569578  inline bool operator==(const path& lhs, const path& rhs)              { return lhs.native() == rhs.native(); }
    570579  inline bool operator==(const path& lhs, const path::string_type& rhs) { return lhs.native() == rhs; }
    571580  inline bool operator==(const path& lhs, const path::value_type* rhs)  { return lhs.native() == rhs; }
    572581  inline bool operator==(const path::string_type& lhs, const path& rhs) { return lhs == rhs.native(); }
    573582  inline bool operator==(const path::value_type* lhs, const path& rhs)  { return lhs == rhs.native(); }
     583
     584  inline std::size_t hash_value(const path& x)
     585  {
     586    return hash_range(x.native().begin(), x.native().end());
     587  }
    574588# endif
    575589
    576590  inline bool operator!=(const path& lhs, const path& rhs)              { return !(lhs == rhs); }
  • libs/filesystem/v3/test/path_unit_test.cpp

     
    4343#include <boost/detail/lightweight_test.hpp>
    4444#include <boost/detail/lightweight_main.hpp>
    4545#include <boost/smart_ptr.hpp>  // used constructor tests
     46#include <boost/functional/hash.hpp>
    4647
    4748#include <iostream>
    4849#include <iomanip>
     
    399400  {
    400401    std::cout << "testing relationals..." << std::endl;
    401402
     403    boost::hash<path> hash;
     404
    402405# ifdef BOOST_WINDOWS_API
    403406    // this is a critical use case to meet user expectations
    404407    CHECK(path("c:\\abc") == path("c:/abc"));
     408    CHECK(hash(path("c:\\abc")) == hash(path("c:/abc")));
    405409# endif
    406410
    407411    const path p("bar");
     
    431435    CHECK(L"baz" == p2);
    432436    CHECK(wstring(L"baz") == p2);
    433437
     438    CHECK(hash(p) == hash(p));
     439    CHECK(hash(p) != hash(p2)); // Not strictly required, but desirable
     440
    434441    CHECK(!(p != p));
    435442    CHECK(p != p2);
    436443    CHECK(p2 != p);