mirror of
https://github.com/microsoft/GSL.git
synced 2026-07-05 08:00:49 +02:00
gsl::not_null: C.89: Make a hash noexcept (#1236)
Without this change, the guideline https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c89-make-a-hash-noexcept would be violated. The test fails before the changes here: ``` tests/pointers_tests.cpp:102:23: error: static assertion failed due to requirement 'noexcept(std::hash<gsl::not_null<std::shared_ptr<int>>>{}(std::declval()))': gsl::not_null hash operator must be noexcept 102 | static_assert(noexcept(std::hash<Key>{}(std::declval<Key>())), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tests/pointers_tests.cpp:108:23: error: static assertion failed due to requirement 'noexcept(std::hash<gsl::strict_not_null<std::shared_ptr<int>>>{}(std::declval()))': gsl::strict_not_null hash operator must be noexcept 108 | static_assert(noexcept(std::hash<Key>{}(std::declval<Key>())), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <gsl/pointers>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
@@ -98,4 +99,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
|
||||
|
||||
Reference in New Issue
Block a user