From d8c70d50503814f712139c0ea67559b2b55f9692 Mon Sep 17 00:00:00 2001 From: barracuda156 Date: Sat, 19 Aug 2023 10:58:46 +0800 Subject: [PATCH 3/3] Revert "util/Concepts: remove obsolete fallbacks" This reverts commit 7c88215acb5c1ddd924c53fb6be152cef22a0535. --- src/util/Concepts.hxx | 30 +++++++++++++++++++++++++++++- src/util/IntrusiveList.hxx | 2 +- src/util/SortList.hxx | 6 +++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git src/util/Concepts.hxx src/util/Concepts.hxx index a741d690..6439dd92 100644 --- src/util/Concepts.hxx +++ src/util/Concepts.hxx @@ -5,5 +5,33 @@ #include +/** + * Compatibility wrapper for std::invocable which is unavailable in + * the Android NDK r25b and Apple Xcode. + */ +#if !defined(ANDROID) && !defined(__APPLE__) +template +concept Invocable = std::invocable; +#else +template +concept Invocable = requires(F f, Args... args) { + { f(args...) }; +}; +#endif + +/** + * Compatibility wrapper for std::predicate which is unavailable in + * the Android NDK r25b and Apple Xcode. + */ +#if !defined(ANDROID) && !defined(__APPLE__) +template +concept Predicate = std::predicate; +#else +template +concept Predicate = requires(F f, Args... args) { + { f(args...) } -> std::same_as; +}; +#endif + template -concept Disposer = std::invocable; +concept Disposer = Invocable; diff --git src/util/IntrusiveList.hxx src/util/IntrusiveList.hxx index aa1c67e5..0467f2c6 100644 --- src/util/IntrusiveList.hxx +++ src/util/IntrusiveList.hxx @@ -266,7 +266,7 @@ public: /** * @return the number of removed items */ - std::size_t remove_and_dispose_if(std::predicate auto pred, + std::size_t remove_and_dispose_if(Predicate auto pred, Disposer auto dispose) noexcept { std::size_t result = 0; diff --git src/util/SortList.hxx src/util/SortList.hxx index 54a43745..6856872b 100644 --- src/util/SortList.hxx +++ src/util/SortList.hxx @@ -3,10 +3,10 @@ #pragma once +#include "Concepts.hxx" #include "StaticVector.hxx" #include // for std::find_if() -#include /** * Move all items from #src to #dest, keeping both sorted. @@ -17,7 +17,7 @@ template constexpr void MergeList(List &dest, List &src, - std::predicate auto p) noexcept + Predicate auto p) noexcept { const auto dest_end = dest.end(), src_end = src.end(); @@ -59,7 +59,7 @@ MergeList(List &dest, List &src, template constexpr void SortList(List &list, - std::predicate auto p) noexcept + Predicate auto p) noexcept { using std::swap;