Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/gsl/pointers
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ not_null<T> operator+(std::ptrdiff_t, const not_null<T>&) = delete;
template <class T, class U = typename T::element_type, bool = std::is_default_constructible<std::hash<U>>::value>
struct not_null_hash
{
std::size_t operator()(const T& value) const { return std::hash<U>{}(value.get()); }
std::size_t operator()(const T& value) const noexcept { return std::hash<U>{}(value.get()); }
};

template <class T, class U>
Expand Down
16 changes: 16 additions & 0 deletions tests/pointers_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <gsl/pointers>

#include <functional>
#include <memory>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -94,4 +95,19 @@ TEST(pointers_test, member_types)
"check member type: element_type");
}

TEST(pointers_test, hash_noexcept_compiles)
{
{
using Key = gsl::not_null<std::shared_ptr<int>>;
static_assert(noexcept(std::hash<Key>{}(std::declval<Key>())),
"gsl::not_null hash operator must be noexcept");
}

{
using Key = gsl::strict_not_null<std::shared_ptr<int>>;
static_assert(noexcept(std::hash<Key>{}(std::declval<Key>())),
"gsl::strict_not_null hash operator must be noexcept");
}
}

} // namespace
Loading