Skip to content

Commit 1b611fb

Browse files
trflynn89gmta
authored andcommitted
AK: Ensure Utf16FlyString is hash-compatible with Utf16View/Utf16String
1 parent 274f8ee commit 1b611fb

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

AK/Utf16FlyString.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,22 @@ struct Formatter<Utf16FlyString> : Formatter<Utf16String> {
165165
}
166166
};
167167

168+
namespace Detail {
169+
170+
template<>
171+
inline constexpr bool IsHashCompatible<Utf16View, Utf16FlyString> = true;
172+
173+
template<>
174+
inline constexpr bool IsHashCompatible<Utf16FlyString, Utf16View> = true;
175+
176+
template<>
177+
inline constexpr bool IsHashCompatible<Utf16String, Utf16FlyString> = true;
178+
179+
template<>
180+
inline constexpr bool IsHashCompatible<Utf16FlyString, Utf16String> = true;
181+
182+
}
183+
168184
}
169185

170186
[[nodiscard]] ALWAYS_INLINE AK::Utf16FlyString operator""_utf16_fly_string(char const* string, size_t length)

Tests/AK/TestUtf16FlyString.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
#include <AK/Utf16FlyString.h>
1010

11+
static_assert(AK::Concepts::HashCompatible<Utf16String, Utf16FlyString>);
12+
static_assert(AK::Concepts::HashCompatible<Utf16FlyString, Utf16String>);
13+
14+
static_assert(AK::Concepts::HashCompatible<Utf16View, Utf16FlyString>);
15+
static_assert(AK::Concepts::HashCompatible<Utf16FlyString, Utf16View>);
16+
1117
TEST_CASE(empty_string)
1218
{
1319
Utf16FlyString fly {};

Tests/AK/TestUtf16String.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include <AK/Utf16String.h>
1515
#include <AK/Utf32View.h>
1616

17+
static_assert(AK::Concepts::HashCompatible<Utf16String, Utf16View>);
18+
static_assert(AK::Concepts::HashCompatible<Utf16View, Utf16String>);
19+
1720
static Utf16String make_copy(Utf16String const& string)
1821
{
1922
return string.has_ascii_storage()

0 commit comments

Comments
 (0)