From 45a2008aa6c7c43da6182cb3d6c96b7ab86902ac Mon Sep 17 00:00:00 2001 From: lizzie Date: Fri, 7 Nov 2025 17:03:01 +0100 Subject: [PATCH] [common] replace Common::(DerivedFrom, IsArithmetic, Size, ConvertibleTo, IsIntegral) with libstdc++ equivalents (#290) Signed-off-by: lizzie Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/290 Reviewed-by: crueter Reviewed-by: Caio Oliveira Co-authored-by: lizzie Co-committed-by: lizzie --- src/common/concepts.h | 23 +++-------------------- src/common/fixed_point.h | 15 +++++++++++---- src/core/file_sys/fs_path_utility.h | 6 ++---- src/core/hle/kernel/k_priority_queue.h | 9 ++++----- src/core/hle/service/sm/sm.h | 7 +++++-- src/core/loader/loader.cpp | 3 ++- src/video_core/gpu_thread.cpp | 4 +--- 7 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src/common/concepts.h b/src/common/concepts.h index 61df1d32a2..4c07443bac 100644 --- a/src/common/concepts.h +++ b/src/common/concepts.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -12,24 +15,4 @@ namespace Common { template concept IsContiguousContainer = std::contiguous_iterator; -// TODO: Replace with std::derived_from when the header -// is available on all supported platforms. -template -concept DerivedFrom = requires { - std::is_base_of_v; - std::is_convertible_v; - }; - -// TODO: Replace with std::convertible_to when libc++ implements it. -template -concept ConvertibleTo = std::is_convertible_v; - -// No equivalents in the stdlib - -template -concept IsArithmetic = std::is_arithmetic_v; - -template -concept IsIntegral = std::is_integral_v; - } // namespace Common diff --git a/src/common/fixed_point.h b/src/common/fixed_point.h index b0f3ae2ccb..c52c870812 100644 --- a/src/common/fixed_point.h +++ b/src/common/fixed_point.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: 2015 Evan Teran // SPDX-License-Identifier: MIT @@ -16,6 +19,10 @@ namespace Common { +// No equivalent for "std::arithmetic" in the stdlib +template +concept IsArithmetic = std::is_arithmetic_v; + template class FixedPoint; @@ -392,13 +399,13 @@ public: // binary math operators, effects underlying bit pattern since these return *this; } - template + template constexpr FixedPoint& operator>>=(Integer n) { data_ >>= n; return *this; } - template + template constexpr FixedPoint& operator<<=(Integer n) { data_ <<= n; return *this; @@ -587,12 +594,12 @@ constexpr FixedPoint operator/(Number lhs, FixedPoint rhs) { } // shift operators -template +template constexpr FixedPoint operator<<(FixedPoint lhs, Integer rhs) { lhs <<= rhs; return lhs; } -template +template constexpr FixedPoint operator>>(FixedPoint lhs, Integer rhs) { lhs >>= rhs; return lhs; diff --git a/src/core/file_sys/fs_path_utility.h b/src/core/file_sys/fs_path_utility.h index 9b6addb64f..a18b54437c 100644 --- a/src/core/file_sys/fs_path_utility.h +++ b/src/core/file_sys/fs_path_utility.h @@ -63,12 +63,10 @@ constexpr bool IsInvalidCharacter(char c) { return impl::IsInvalidCharacterImpl(c); } constexpr bool IsInvalidCharacterForHostName(char c) { - return impl::IsInvalidCharacterImpl(c); + return impl::IsInvalidCharacterImpl(c); } constexpr bool IsInvalidCharacterForMountName(char c) { - return impl::IsInvalidCharacterImpl(c); + return impl::IsInvalidCharacterImpl(c); } } // namespace StringTraits diff --git a/src/core/hle/kernel/k_priority_queue.h b/src/core/hle/kernel/k_priority_queue.h index 99347b5aef..89a0c5bbea 100644 --- a/src/core/hle/kernel/k_priority_queue.h +++ b/src/core/hle/kernel/k_priority_queue.h @@ -15,7 +15,6 @@ #include "common/alignment.h" #include "common/assert.h" #include "common/common_types.h" -#include "common/concepts.h" namespace Kernel { @@ -24,7 +23,7 @@ class KThread; template concept KPriorityQueueAffinityMask = ! std::is_reference_v&& requires(T& t) { - { t.GetAffinityMask() } -> Common::ConvertibleTo; + { t.GetAffinityMask() } -> std::convertible_to; { t.SetAffinityMask(0) }; { t.GetAffinity(0) } -> std::same_as; @@ -50,9 +49,9 @@ std::is_reference_v&& requires(T& t) { std::remove_cvref_t() } -> KPriorityQueueAffinityMask; - { t.GetActiveCore() } -> Common::ConvertibleTo; - { t.GetPriority() } -> Common::ConvertibleTo; - { t.IsDummyThread() } -> Common::ConvertibleTo; + { t.GetActiveCore() } -> std::convertible_to; + { t.GetPriority() } -> std::convertible_to; + { t.IsDummyThread() } -> std::convertible_to; }; template diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index 32c218638d..d5f372b97d 100644 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -8,8 +11,8 @@ #include #include #include +#include -#include "common/concepts.h" #include "core/hle/kernel/k_port.h" #include "core/hle/kernel/svc.h" #include "core/hle/result.h" @@ -63,7 +66,7 @@ public: Result UnregisterService(const std::string& name); Result GetServicePort(Kernel::KClientPort** out_client_port, const std::string& name); - template T> + template T> std::shared_ptr GetService(const std::string& service_name, bool block = false) const { auto service = registered_services.find(service_name); if (service == registered_services.end() && !block) { diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 1f0bc4d2c1..4379634d03 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "common/concepts.h" #include "common/fs/path_util.h" #include "common/logging/log.h" @@ -27,7 +28,7 @@ namespace Loader { namespace { -template T> +template T> std::optional IdentifyFileLoader(FileSys::VirtualFile file) { const auto file_type = T::IdentifyType(file); if (file_type != FileType::Error) { diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp index 8739905d99..af09365ec6 100644 --- a/src/video_core/gpu_thread.cpp +++ b/src/video_core/gpu_thread.cpp @@ -23,9 +23,7 @@ namespace VideoCommon::GPUThread { static void RunThread(std::stop_token stop_token, Core::System& system, VideoCore::RendererBase& renderer, Core::Frontend::GraphicsContext& context, Tegra::Control::Scheduler& scheduler, SynchState& state) { - std::string name = "GPU"; - - Common::SetCurrentThreadName(name.c_str()); + Common::SetCurrentThreadName("GPU"); Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical); system.RegisterHostThread();