Skip to content

Commit fe90476

Browse files
authored
Remove std::hash specializations (#219)
`std::fstream`, the main inspiration for `file`, does not define a specialization of `std::hash` `std::filesystem::directory_iterator`, the C++ open directory abstraction, also does not Given that storing `file` or `directory` in hashmaps is even less sensible, this pr removes the `hash` specializations
1 parent 3c3315e commit fe90476

File tree

4 files changed

+0
-32
lines changed

4 files changed

+0
-32
lines changed

include/tmp/directory

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,4 @@ private:
7474
};
7575
} // namespace tmp
7676

77-
/// The template specialization of `std::hash` for `tmp::directory`
78-
template<> struct std::hash<tmp::directory> {
79-
std::size_t operator()(const tmp::directory& directory) const noexcept {
80-
// `std::hash<std::filesystem::path>` was not included in the C++17 standard
81-
return filesystem::hash_value(directory);
82-
}
83-
};
84-
8577
#endif // TMP_DIRECTORY_H

include/tmp/file

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,4 @@ private:
8686
};
8787
} // namespace tmp
8888

89-
/// The template specialization of `std::hash` for `tmp::file`
90-
template<> struct std::hash<tmp::file> {
91-
std::size_t operator()(const tmp::file& file) const noexcept {
92-
return std::hash<tmp::file::native_handle_type>()(file.native_handle());
93-
}
94-
};
95-
9689
#endif // TMP_FILE_H

tests/directory.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,5 @@ TEST(directory, swap) {
152152
EXPECT_EQ(fst.path(), snd_path);
153153
EXPECT_EQ(snd.path(), fst_path);
154154
}
155-
156-
/// Tests directory hashing
157-
TEST(directory, hash) {
158-
directory tmpdir = directory();
159-
std::hash hash = std::hash<directory>();
160-
161-
EXPECT_EQ(hash(tmpdir), fs::hash_value(tmpdir.path()));
162-
}
163155
} // namespace
164156
} // namespace tmp

tests/file.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,5 @@ TEST(file, swap) {
148148
EXPECT_TRUE(is_open(fst));
149149
EXPECT_TRUE(is_open(snd));
150150
}
151-
152-
/// Tests file hashing
153-
TEST(file, hash) {
154-
file tmpfile = file();
155-
std::hash hash = std::hash<file>();
156-
157-
EXPECT_EQ(hash(tmpfile),
158-
std::hash<file::native_handle_type>()(tmpfile.native_handle()));
159-
}
160151
} // namespace
161152
} // namespace tmp

0 commit comments

Comments
 (0)