mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
AK: Ensure string types are actually considered hash-compatible
The AnyString concept is currently broken because it checks whether a StringView is constructible from a type T. The StringView constructors, however, only accept constant rvalue references - i.e. `T const&`. This also adds a test to ensure this continues to work.
This commit is contained in:
parent
2f67f2ba3d
commit
f31bd190b0
2 changed files with 25 additions and 1 deletions
|
@ -49,7 +49,7 @@ template<typename T, typename S>
|
||||||
concept DerivedFrom = IsBaseOf<S, T>;
|
concept DerivedFrom = IsBaseOf<S, T>;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept AnyString = IsConstructible<StringView, T>;
|
concept AnyString = IsConstructible<StringView, RemoveCVReference<T> const&>;
|
||||||
|
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
concept HashCompatible = IsHashCompatible<Detail::Decay<T>, Detail::Decay<U>>;
|
concept HashCompatible = IsHashCompatible<Detail::Decay<T>, Detail::Decay<U>>;
|
||||||
|
|
|
@ -6,9 +6,33 @@
|
||||||
|
|
||||||
#include <LibTest/TestCase.h>
|
#include <LibTest/TestCase.h>
|
||||||
|
|
||||||
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/Concepts.h>
|
||||||
|
#include <AK/FlyString.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/StringUtils.h>
|
#include <AK/StringUtils.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
|
TEST_CASE(hash_compatible)
|
||||||
|
{
|
||||||
|
static_assert(AK::Concepts::HashCompatible<String, StringView>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<String, FlyString>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<StringView, String>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<StringView, FlyString>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<FlyString, String>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<FlyString, StringView>);
|
||||||
|
|
||||||
|
static_assert(AK::Concepts::HashCompatible<DeprecatedString, StringView>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<DeprecatedString, DeprecatedFlyString>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<StringView, DeprecatedString>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<StringView, DeprecatedFlyString>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<DeprecatedFlyString, DeprecatedString>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<DeprecatedFlyString, StringView>);
|
||||||
|
|
||||||
|
static_assert(AK::Concepts::HashCompatible<StringView, ByteBuffer>);
|
||||||
|
static_assert(AK::Concepts::HashCompatible<ByteBuffer, StringView>);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE(matches_null)
|
TEST_CASE(matches_null)
|
||||||
{
|
{
|
||||||
EXPECT(AK::StringUtils::matches(StringView(), StringView()));
|
EXPECT(AK::StringUtils::matches(StringView(), StringView()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue