From b99fc701912e7ef87a6c1a7aca7ec285279da43a Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 31 Mar 2021 14:19:26 -0700 Subject: common: common_funcs: Add helper macros for non-copyable and non-moveable. - Useful for scenarios where we do not want to inherit from NonCopyable. --- src/common/common_funcs.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/common') diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 4ace2cd33..73c8c9354 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -108,6 +108,14 @@ __declspec(dllimport) void __stdcall DebugBreak(void); } \ } +#define NON_COPYABLE(cls) \ + cls(const cls&) = delete; \ + cls& operator=(const cls&) = delete + +#define NON_MOVEABLE(cls) \ + cls(cls&&) = delete; \ + cls& operator=(cls&&) = delete + #define R_SUCCEEDED(res) (res.IsSuccess()) /// Evaluates an expression that returns a result, and returns the result if it would fail. -- cgit v1.2.3 From d9205f82b35c61de9eaa381578f4aceaf94b75b1 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 31 Mar 2021 14:35:46 -0700 Subject: common: intrusive_red_black_tree: Disable static_assert that will not evaluate as constant on MSVC. --- src/common/intrusive_red_black_tree.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/common') diff --git a/src/common/intrusive_red_black_tree.h b/src/common/intrusive_red_black_tree.h index c0bbcd457..15f972054 100644 --- a/src/common/intrusive_red_black_tree.h +++ b/src/common/intrusive_red_black_tree.h @@ -509,7 +509,11 @@ private: private: static constexpr TypedStorage DerivedStorage = {}; + +#ifndef _MSC_VER + // TODO(bunnei): Enable on MSVC once this can be const evaluated by the compiler static_assert(GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage)); +#endif }; template > -- cgit v1.2.3 From 74120c5e3a721bb05840873e88cddad0e966f17d Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 1 Apr 2021 14:47:35 -0700 Subject: common: bit_util: Add BIT macro. --- src/common/bit_util.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/common') diff --git a/src/common/bit_util.h b/src/common/bit_util.h index 64520ca4e..683f09158 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h @@ -44,4 +44,6 @@ template return static_cast(log2_f + static_cast((value ^ (1ULL << log2_f)) != 0ULL)); } +#define BIT(n) (1U << (n)) + } // namespace Common -- cgit v1.2.3 From 02c2b28cd0f341fd955f9648d9174777e0b60689 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 1 Apr 2021 23:04:54 -0700 Subject: common: common_funcs: Add Size helper function. --- src/common/common_funcs.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/common') diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 73c8c9354..19bb021e0 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -136,4 +136,19 @@ namespace Common { return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; } +// std::size() does not support zero-size C arrays. We're fixing that. +template +constexpr auto Size(const C& c) -> decltype(c.size()) { + return std::size(c); +} + +template +constexpr std::size_t Size(const C& c) { + if constexpr (sizeof(C) == 0) { + return 0; + } else { + return std::size(c); + } +} + } // namespace Common -- cgit v1.2.3 From d3c166d4d5fddb0c19c0219a3efdc85907ebce31 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 1 May 2021 12:22:14 -0700 Subject: common: Rename NON_COPYABLE/NON_MOVABLE with YUZU_ prefix. --- src/common/common_funcs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/common') diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 19bb021e0..17d1ee86b 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -108,11 +108,11 @@ __declspec(dllimport) void __stdcall DebugBreak(void); } \ } -#define NON_COPYABLE(cls) \ +#define YUZU_NON_COPYABLE(cls) \ cls(const cls&) = delete; \ cls& operator=(const cls&) = delete -#define NON_MOVEABLE(cls) \ +#define YUZU_NON_MOVEABLE(cls) \ cls(cls&&) = delete; \ cls& operator=(cls&&) = delete -- cgit v1.2.3 From 27a6ef64fd06b7fd5de8d3dc9a3939368593b808 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 1 May 2021 14:16:26 -0700 Subject: fixup! common: intrusive_red_black_tree: Disable static_assert that will not evaluate as constant on MSVC. --- src/common/intrusive_red_black_tree.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/common') diff --git a/src/common/intrusive_red_black_tree.h b/src/common/intrusive_red_black_tree.h index 15f972054..1f696fe80 100644 --- a/src/common/intrusive_red_black_tree.h +++ b/src/common/intrusive_red_black_tree.h @@ -509,11 +509,6 @@ private: private: static constexpr TypedStorage DerivedStorage = {}; - -#ifndef _MSC_VER - // TODO(bunnei): Enable on MSVC once this can be const evaluated by the compiler - static_assert(GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage)); -#endif }; template > -- cgit v1.2.3 From e02785be83dd3d02a8fc7aebc13337546f04bab8 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 1 May 2021 14:32:36 -0700 Subject: common: parent_of_member: Fix build for OffsetOf(). --- src/common/parent_of_member.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/common') diff --git a/src/common/parent_of_member.h b/src/common/parent_of_member.h index d9a14529d..e0f8ab5c8 100644 --- a/src/common/parent_of_member.h +++ b/src/common/parent_of_member.h @@ -133,27 +133,27 @@ template using GetMemberType = typename GetMemberPointerTraits::Member; template > -static inline std::ptrdiff_t OffsetOf = [] { +constexpr std::ptrdiff_t OffsetOf() { using DeducedParentType = GetParentType; using MemberType = GetMemberType; static_assert(std::is_base_of::value || std::is_same::value); return OffsetOfCalculator::OffsetOf(MemberPtr); -}(); +}; } // namespace impl template > constexpr RealParentType& GetParentReference(impl::GetMemberType* member) { - std::ptrdiff_t Offset = impl::OffsetOf; + std::ptrdiff_t Offset = impl::OffsetOf(); return *static_cast( static_cast(static_cast(static_cast(member)) - Offset)); } template > constexpr RealParentType const& GetParentReference(impl::GetMemberType const* member) { - std::ptrdiff_t Offset = impl::OffsetOf; + std::ptrdiff_t Offset = impl::OffsetOf(); return *static_cast(static_cast( static_cast(static_cast(member)) - Offset)); } -- cgit v1.2.3 From a488b86e97df2bf188938f01fb484aa420298fef Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 4 May 2021 20:53:45 -0700 Subject: fixup! common: bit_util: Add BIT macro. --- src/common/bit_util.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/common') diff --git a/src/common/bit_util.h b/src/common/bit_util.h index 683f09158..64520ca4e 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h @@ -44,6 +44,4 @@ template return static_cast(log2_f + static_cast((value ^ (1ULL << log2_f)) != 0ULL)); } -#define BIT(n) (1U << (n)) - } // namespace Common -- cgit v1.2.3