GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::filesystem::hash_value(3) C++ Standard Libary std::filesystem::hash_value(3)

std::filesystem::hash_value - std::filesystem::hash_value


Defined in header <filesystem>
std::size_t hash_value( const std::filesystem::path& p ) noexcept; (since C++17)


p - a std::filesystem::path object


A hash value such that if for two paths, p1 == p2 then hash_value(p1) ==
hash_value(p2).


The return value is consistent with std::hash.


Equality of two paths is determined by comparing each component separately, so, for
example "a//b" equals "a/b" and has the same hash_value


hash_value originates from the Boost.filesystem library where it was used for
interoperability with boost.hash (which calls hash_value found by argument-dependent
lookup or boost::hash_value where available).

// Run this code


#include <cassert>
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <filesystem>
#include <unordered_set>
namespace fs = std::filesystem;


void show_hash(fs::path const& p)
{
std::cout << std::hex << std::uppercase << std::setw(16)
<< fs::hash_value(p) << " : " << p << '\n';
}


int main()
{
auto tmp1 = fs::path{"/tmp"};
auto tmp2 = fs::path{"/tmp/../tmp"};
assert( ! (tmp1 == tmp2) );
assert( fs::equivalent(tmp1, tmp2) );
show_hash( tmp1 );
show_hash( tmp2 );


for (auto s : {"/a///b", "/a//b", "/a/c", "...", "..", ".", ""})
show_hash(s);


// A hash function object to work with unordered_* containers:
struct PathHash {
std::size_t operator()(fs::path const& p) const noexcept {
return fs::hash_value(p);
}
};
std::unordered_set<fs::path, PathHash> dirs {
"/bin", "/bin", "/lib", "/lib", "/opt", "/opt", "/tmp", "/tmp/../tmp"
};
for (fs::path const& p: dirs) { std::cout << p << ' '; }
}


6050C47ADB62DFE5 : "/tmp"
62795A58B69AD90A : "/tmp/../tmp"
FF302110C9991974 : "/a///b"
FF302110C9991974 : "/a//b"
FD6167277915D464 : "/a/c"
C42040F82CD8B542 : "..."
D2D30154E0B78BBC : ".."
D18C722215ED0530 : "."
0 : ""
"/tmp/../tmp" "/opt" "/lib" "/tmp" "/bin"


compares the lexical representations of two paths
compare lexicographically
(public member function)
operator==
operator!=
operator<
operator<=
operator>
operator>= lexicographically compares two paths
operator<=> (function)
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(C++20)
equivalent checks whether two paths refer to the same file
(C++17) system object
(function)
hash hash function object
(C++11) (class template)
std::hash<std::filesystem::path> hash support for std::filesystem::path
(C++17) (class template specialization)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.