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/common_funcs.h') 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 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/common_funcs.h') 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/common_funcs.h') 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