mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
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.
This commit is contained in:
@ -5,9 +5,19 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <version>
|
||||
|
||||
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 <std::input_iterator I, std::sentinel_for<I> 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
|
||||
|
Reference in New Issue
Block a user