diff --git a/src/util/Concepts.hxx b/src/util/Concepts.hxx new file mode 100644 index 000000000..d24ddc5a8 --- /dev/null +++ b/src/util/Concepts.hxx @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Max Kellermann + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include + +/** + * 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 diff --git a/src/util/SortList.hxx b/src/util/SortList.hxx index 42817340c..57139e0bd 100644 --- a/src/util/SortList.hxx +++ b/src/util/SortList.hxx @@ -29,10 +29,10 @@ #pragma once +#include "Concepts.hxx" #include "StaticVector.hxx" #include // for std::find_if() -#include // for std::predicate /** * Move all items from #src to #dest, keeping both sorted. @@ -43,11 +43,7 @@ template constexpr void MergeList(List &dest, List &src, -#if !defined(ANDROID) && !defined(__APPLE__) - /* Android NDK r25b has no std::predicate */ - std::predicate -#endif - auto p) noexcept + Predicate auto p) noexcept { const auto dest_end = dest.end(), src_end = src.end(); @@ -89,11 +85,7 @@ MergeList(List &dest, List &src, template constexpr void SortList(List &list, -#if !defined(ANDROID) && !defined(__APPLE__) - /* Android NDK r25b has no std::predicate */ - std::predicate -#endif - auto p) noexcept + Predicate auto p) noexcept { using std::swap;