compare ops hashed_string with string_view

This commit is contained in:
BlackMATov
2023-02-03 02:17:25 +07:00
parent 0a4ba7b128
commit 2c9dc25e9d
3 changed files with 13 additions and 0 deletions

View File

@@ -77,12 +77,17 @@ TEST_CASE("meta/meta_base/hashed_string") {
constexpr hashed_string hs2{"hello"}; constexpr hashed_string hs2{"hello"};
static_assert(!(hs1 < hs2) && !(hs2 < hs1)); static_assert(!(hs1 < hs2) && !(hs2 < hs1));
static_assert(hs1 < hashed_string{"world"} || hashed_string{"world"} < hs1); static_assert(hs1 < hashed_string{"world"} || hashed_string{"world"} < hs1);
static_assert((hs1 < "world" || hs1 > "world"));
static_assert(("world" < hs1 || "world" > hs1));
} }
SUBCASE("operator==") { SUBCASE("operator==") {
constexpr hashed_string hs1{"hello"}; constexpr hashed_string hs1{"hello"};
static_assert(hs1 == hashed_string{"hello"}); static_assert(hs1 == hashed_string{"hello"});
static_assert(hs1 != hashed_string{"world"}); static_assert(hs1 != hashed_string{"world"});
static_assert(hs1 == "hello");
static_assert("hello" == hs1);
static_assert("world" != hs1);
} }
SUBCASE("swap") { SUBCASE("swap") {

View File

@@ -45,6 +45,12 @@ namespace meta_hpp::detail
}; };
constexpr void swap(hashed_string& l, hashed_string& r) noexcept { l.swap(r); } constexpr void swap(hashed_string& l, hashed_string& r) noexcept { l.swap(r); }
[[nodiscard]] constexpr bool operator==(hashed_string l, std::string_view r) noexcept { return l == hashed_string{r}; }
[[nodiscard]] constexpr bool operator==(std::string_view l, hashed_string r) noexcept { return hashed_string{l} == r; }
[[nodiscard]] constexpr std::strong_ordering operator<=>(hashed_string l, std::string_view r) noexcept { return l <=> hashed_string{r}; }
[[nodiscard]] constexpr std::strong_ordering operator<=>(std::string_view l, hashed_string r) noexcept { return hashed_string{l} <=> r; }
} }
namespace std namespace std

View File

@@ -55,6 +55,8 @@ namespace meta_hpp::detail
return id; return id;
} }
}; };
inline void swap(type_id& l, type_id& r) noexcept { l.swap(r); }
} }
namespace std namespace std