diff --git a/AK/GenericShorthands.h b/AK/GenericShorthands.h index 57f7f8a32f4..06fe1bba743 100644 --- a/AK/GenericShorthands.h +++ b/AK/GenericShorthands.h @@ -41,6 +41,12 @@ template return (... || (forward(to_compare) >= forward(valid_values))); } +template +[[nodiscard]] constexpr bool first_is_equal_to_all_of(T&& to_compare, Ts&&... valid_values) +{ + return (... && (forward(to_compare) == forward(valid_values))); +} + template [[nodiscard]] constexpr bool first_is_smaller_than_all_of(T&& to_compare, Ts&&... valid_values) { @@ -67,6 +73,7 @@ template } #if USING_AK_GLOBALLY +using AK::first_is_equal_to_all_of; using AK::first_is_larger_or_equal_than_all_of; using AK::first_is_larger_or_equal_than_one_of; using AK::first_is_larger_than_all_of; diff --git a/Tests/AK/TestGenericShorthands.cpp b/Tests/AK/TestGenericShorthands.cpp index 41af2da3104..6529281032b 100644 --- a/Tests/AK/TestGenericShorthands.cpp +++ b/Tests/AK/TestGenericShorthands.cpp @@ -203,6 +203,27 @@ TEST_CASE(first_is_larger_than_one_of) EXPECT(!first_is_larger_than_one_of(10)); } +TEST_CASE(first_is_equal_to_all_of) +{ + static_assert(first_is_equal_to_all_of(1)); + EXPECT(first_is_equal_to_all_of(1)); + + static_assert(first_is_equal_to_all_of(1, 1)); + EXPECT(first_is_equal_to_all_of(1, 1)); + + static_assert(!first_is_equal_to_all_of(1, 2)); + EXPECT(!first_is_equal_to_all_of(1, 2)); + + static_assert(!first_is_equal_to_all_of(1, 1, 2)); + EXPECT(!first_is_equal_to_all_of(1, 1, 2)); + + static_assert(!first_is_equal_to_all_of(2, 1, 1)); + EXPECT(!first_is_equal_to_all_of(2, 1, 1)); + + static_assert(!first_is_equal_to_all_of(2, 2, 1)); + EXPECT(!first_is_equal_to_all_of(2, 2, 1)); +} + TEST_CASE(first_is_larger_or_equal_than_all_of) { // Finds larger than all items