Further unique_ref improvements

This commit is contained in:
Sebastian Messmer 2017-04-03 19:08:41 +01:00
parent 2fb61e7c71
commit ed9f224f19
2 changed files with 3 additions and 2 deletions

View File

@ -28,6 +28,7 @@ namespace cpputils {
template<class T, class D = std::default_delete<T>>
class unique_ref final {
public:
// TODO Add assert != nullptr to all calls (also move constructors, ...) and test performance impact (maybe disable assertions in prod?)
using element_type = typename std::unique_ptr<T, D>::element_type;
using deleter_type = typename std::unique_ptr<T, D>::deleter_type;
using pointer = typename std::unique_ptr<T, D>::pointer;
@ -167,7 +168,7 @@ namespace std {
// Allow using it in std::unordered_set / std::unordered_map
template<class T, class D> struct hash<cpputils::unique_ref<T, D>> {
size_t operator()(const cpputils::unique_ref<T, D> &ref) const noexcept {
return (size_t)_extract_ptr(ref);
return std::hash<typename cpputils::unique_ref<T,D>::pointer>()(_extract_ptr(ref));
}
};

View File

@ -428,7 +428,7 @@ TEST_F(UniqueRefTest, NullptrIsLess2) {
unique_ref<int> var1 = make_unique_ref<int>(3);
unique_ref<int> var2 = make_unique_ref<int>(3);
makeInvalid(std::move(var2));
EXPECT_TRUE(std::less<unique_ref<int>>()(var2, var1));
EXPECT_FALSE(std::less<unique_ref<int>>()(var1, var2));
}
TEST_F(UniqueRefTest, NullptrIsNotLessThanNullptr) {