Replace template conditionals with C++20 requires clause

Related: https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-constraints.html

PR #19424.
This commit is contained in:
Chocobo1
2023-08-09 20:33:19 +08:00
committed by GitHub
parent 33d767b765
commit 5c06d0aa75
6 changed files with 23 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2023 Mike Tzou (Chocobo1)
* Copyright (C) 2018 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
@@ -28,25 +29,16 @@
#pragma once
#include <type_traits>
namespace Algorithm
{
template <typename T, typename = void>
struct HasMappedType
: std::false_type
{
};
template <typename T>
struct HasMappedType<T, std::void_t<typename T::mapped_type>>
: std::true_type
concept HasMappedType = requires
{
typename T::mapped_type;
};
// To be used with associative array types, such as QMap, QHash and its variants
template <typename T, typename BinaryPredicate
, typename std::enable_if_t<HasMappedType<T>::value, int> = 0>
template <HasMappedType T, typename BinaryPredicate>
void removeIf(T &dict, BinaryPredicate &&p)
{
auto it = dict.begin();