From d766c527c798f61510c8830bf32d36fa772e87d3 Mon Sep 17 00:00:00 2001 From: Javier Martinez Date: Tue, 3 Jun 2025 17:39:24 -0400 Subject: [PATCH] Common: Replace Contains and ContainsSubrange with C++23 std::ranges equivalents Common: Use feature macros for better compatibility Common/Contains.h: fix linting issue Common/Contains.h: Add C++23 TODO Common/Contains.h: Fix comment lint issue. --- Source/Core/Common/Contains.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/Core/Common/Contains.h b/Source/Core/Common/Contains.h index cabf6c0c07..8ac66d0151 100644 --- a/Source/Core/Common/Contains.h +++ b/Source/Core/Common/Contains.h @@ -5,9 +5,19 @@ #include #include +#include namespace Common { +#if defined(__cpp_lib_ranges_contains) && __cpp_lib_ranges_contains >= 202202L + +// Use the standard library functions if available (C++23) +inline constexpr auto& Contains = std::ranges::contains; +inline constexpr auto& ContainsSubrange = std::ranges::contains_subrange; + +#else +// TODO C++23: This old implementation likely isn't needed once migrated to C++23. Remove them or +// this file itself. Ad hoc implementations for C++20 struct ContainsFn { template S, class T, class Proj = std::identity> @@ -54,8 +64,8 @@ struct ContainsSubrangeFn } }; -// TODO C++23: Replace with std::ranges::contains. inline constexpr ContainsFn Contains{}; -// TODO C++23: Replace with std::ranges::contains_subrange. inline constexpr ContainsSubrangeFn ContainsSubrange{}; + +#endif } // namespace Common