Adding std::hash<not_null<T>> tests to notnull_tests.cpp (#947)

* added std::hash<not_null> tests

* nl
This commit is contained in:
Jordan Maples [MSFT]
2020-11-03 16:56:09 -08:00
committed by GitHub
parent a150aaa4ed
commit 9150ce9a95

View File

@@ -533,3 +533,18 @@ TEST(notnull_tests, TestMakeNotNull)
}
#endif
}
TEST(notnull_tests, TestStdHash)
{
int x = 42;
int y = 99;
not_null<int*> nn{&x};
const not_null<int*> cnn{&x};
std::hash<not_null<int*>> hash_nn;
std::hash<int*> hash_intptr;
EXPECT_TRUE(hash_nn(nn) == hash_intptr(&x));
EXPECT_FALSE(hash_nn(nn) == hash_intptr(&y));
EXPECT_FALSE(hash_nn(nn) == hash_intptr(nullptr));
}