File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -231,7 +231,7 @@ template <class T>
231231not_null<T> operator+(std::ptrdiff_t, const not_null<T>&) = delete;
232232
233233
234- template <class T, class U = decltype(std::declval<const T&>().get()) , bool = std::is_default_constructible<std::hash<U>>::value>
234+ template <class T, class U = typename T::element_type , bool = std::is_default_constructible<std::hash<U>>::value>
235235struct not_null_hash
236236{
237237 std::size_t operator()(const T& value) const { return std::hash<U>{}(value.get()); }
Original file line number Diff line number Diff line change @@ -735,4 +735,18 @@ TEST(notnull_tests, TestStdHash)
735735 EXPECT_FALSE (hash_nn (nn) == hash_intptr (&y));
736736 EXPECT_FALSE (hash_nn (nn) == hash_intptr (nullptr ));
737737 }
738+
739+ {
740+ auto x = std::make_shared<int >(42 );
741+ auto y = std::make_shared<int >(99 );
742+ not_null<std::shared_ptr<int >> nn{x};
743+ const not_null<std::shared_ptr<int >> cnn{x};
744+
745+ std::hash<not_null<std::shared_ptr<int >>> hash_nn;
746+ std::hash<std::shared_ptr<int >> hash_sharedptr;
747+
748+ EXPECT_TRUE (hash_nn (nn) == hash_sharedptr (x));
749+ EXPECT_FALSE (hash_nn (nn) == hash_sharedptr (y));
750+ EXPECT_TRUE (hash_nn (cnn) == hash_sharedptr (x));
751+ }
738752}
You can’t perform that action at this time.
0 commit comments