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) 2016 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2014 sledgehammer999 <hammered999@gmail.com>
*
@@ -41,10 +42,7 @@
#include "utils/string.h"
template <typename T>
struct IsQFlags : std::false_type {};
template <typename T>
struct IsQFlags<QFlags<T>> : std::true_type {};
concept IsQFlags = std::same_as<T, QFlags<typename T::enum_type>>;
// There are 2 ways for class `T` provide serialization support into `SettingsStorage`:
// 1. If the `T` state is intended for users to edit (via a text editor), then
@@ -76,7 +74,7 @@ public:
const auto value = loadValue<QString>(key);
return Utils::String::toEnum(value, defaultValue);
}
else if constexpr (IsQFlags<T>::value)
else if constexpr (IsQFlags<T>)
{
const typename T::Int value = loadValue(key, static_cast<typename T::Int>(defaultValue));
return T {value};
@@ -101,7 +99,7 @@ public:
storeValueImpl(key, value.toString());
else if constexpr (std::is_enum_v<T>)
storeValueImpl(key, Utils::String::fromEnum(value));
else if constexpr (IsQFlags<T>::value)
else if constexpr (IsQFlags<T>)
storeValueImpl(key, static_cast<typename T::Int>(value));
else
storeValueImpl(key, QVariant::fromValue(value));