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
commit 5c06d0aa75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 31 deletions

View file

@ -67,8 +67,9 @@ namespace Utils::String
QString fromDouble(double n, int precision);
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0>
template <typename T>
QString fromEnum(const T &value)
requires std::is_enum_v<T>
{
static_assert(std::is_same_v<int, typename std::underlying_type_t<T>>,
"Enumeration underlying type has to be int.");
@ -77,8 +78,9 @@ namespace Utils::String
return QString::fromLatin1(metaEnum.valueToKey(static_cast<int>(value)));
}
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0>
template <typename T>
T toEnum(const QString &serializedValue, const T &defaultValue)
requires std::is_enum_v<T>
{
static_assert(std::is_same_v<int, typename std::underlying_type_t<T>>,
"Enumeration underlying type has to be int.");