#include "newtype/newtype.hpp" #include #include #include #include TEMPLATE_TEST_CASE("Hash", "[hash]", std::string, int) { GIVEN("A new_type not deriving nt::Hash") { using type_alias = nt::new_type; static_assert(nt::concepts::hashable); THEN("it is not hashable") { STATIC_REQUIRE_FALSE(nt::concepts::hashable); } } GIVEN("A new_type over a hashable type deriving nt::Hash") { using type_alias = nt::new_type; static_assert(nt::concepts::hashable); THEN("it is hashable") { STATIC_REQUIRE(nt::concepts::hashable); } } GIVEN("A new_type over a non-hashable type deriving nt::Hash") { struct non_hashable { }; using type_alias = nt::new_type; static_assert(!nt::concepts::hashable); THEN("it is not hashable") { STATIC_REQUIRE_FALSE(nt::concepts::hashable); } } GIVEN("A hashable new_type") { using type_alias = nt::new_type; static_assert(nt::concepts::hashable); THEN("it can be used a the key in an unordered_map") { auto map = std::unordered_map{}; map[type_alias{42}] = 43; REQUIRE(map[type_alias{42}] == 43); } } }