util/Concepts: compatibility wrapper for std::predicate
This commit is contained in:
parent
5945877313
commit
00b7535cf1
46
src/util/Concepts.hxx
Normal file
46
src/util/Concepts.hxx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 Max Kellermann <max.kellermann@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <concepts>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compatibility wrapper for std::predicate which is unavailable in
|
||||||
|
* the Android NDK r25b and Apple Xcode.
|
||||||
|
*/
|
||||||
|
#if !defined(ANDROID) && !defined(__APPLE__)
|
||||||
|
template<typename F, typename... Args>
|
||||||
|
concept Predicate = std::predicate<F, Args...>;
|
||||||
|
#else
|
||||||
|
template<typename F, typename... Args>
|
||||||
|
concept Predicate = requires(F f, Args... args) {
|
||||||
|
{ f(args...) } -> std::same_as<bool>;
|
||||||
|
};
|
||||||
|
#endif
|
@ -29,10 +29,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Concepts.hxx"
|
||||||
#include "StaticVector.hxx"
|
#include "StaticVector.hxx"
|
||||||
|
|
||||||
#include <algorithm> // for std::find_if()
|
#include <algorithm> // for std::find_if()
|
||||||
#include <concepts> // for std::predicate
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move all items from #src to #dest, keeping both sorted.
|
* Move all items from #src to #dest, keeping both sorted.
|
||||||
@ -43,11 +43,7 @@
|
|||||||
template<typename List>
|
template<typename List>
|
||||||
constexpr void
|
constexpr void
|
||||||
MergeList(List &dest, List &src,
|
MergeList(List &dest, List &src,
|
||||||
#if !defined(ANDROID) && !defined(__APPLE__)
|
Predicate<typename List::const_reference, typename List::const_reference> auto p) noexcept
|
||||||
/* Android NDK r25b has no std::predicate */
|
|
||||||
std::predicate<typename List::const_reference, typename List::const_reference>
|
|
||||||
#endif
|
|
||||||
auto p) noexcept
|
|
||||||
{
|
{
|
||||||
const auto dest_end = dest.end(), src_end = src.end();
|
const auto dest_end = dest.end(), src_end = src.end();
|
||||||
|
|
||||||
@ -89,11 +85,7 @@ MergeList(List &dest, List &src,
|
|||||||
template<typename List>
|
template<typename List>
|
||||||
constexpr void
|
constexpr void
|
||||||
SortList(List &list,
|
SortList(List &list,
|
||||||
#if !defined(ANDROID) && !defined(__APPLE__)
|
Predicate <typename List::const_reference, typename List::const_reference> auto p) noexcept
|
||||||
/* Android NDK r25b has no std::predicate */
|
|
||||||
std::predicate<typename List::const_reference, typename List::const_reference>
|
|
||||||
#endif
|
|
||||||
auto p) noexcept
|
|
||||||
{
|
{
|
||||||
using std::swap;
|
using std::swap;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user