From f708fc4f9816203fa00cdb5365c685c28894838d Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 13 May 2024 15:16:01 +0800 Subject: [PATCH] some fix --- include/pocketpy/any.h | 9 ++++++--- include/pocketpy/common.h | 3 --- include/pocketpy/linalg.h | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/pocketpy/any.h b/include/pocketpy/any.h index 0035b540..82cad27b 100644 --- a/include/pocketpy/any.h +++ b/include/pocketpy/any.h @@ -5,6 +5,9 @@ namespace pkpy { +template +inline constexpr bool is_any_sso_v = is_pod_v && sizeof(T) <= sizeof(void*); + struct any{ struct vtable{ const std::type_index type; @@ -13,7 +16,7 @@ struct any{ template inline static vtable* get(){ static_assert(std::is_same_v>); - if constexpr (is_sso_v){ + if constexpr (is_any_sso_v){ static vtable vt{ typeid(T), nullptr }; return &vt; }else{ @@ -35,7 +38,7 @@ struct any{ using U = std::decay_t; static_assert(!std::is_same_v, "any(const any&) is deleted"); static_assert(sizeof(U) == sizeof(T)); - if constexpr (is_sso_v){ + if constexpr (is_any_sso_v){ memcpy(&data, &value, sizeof(U)); }else{ data = new U(std::forward(value)); @@ -58,7 +61,7 @@ struct any{ template T& _cast() const noexcept{ static_assert(std::is_same_v>); - if constexpr (is_sso_v){ + if constexpr (is_any_sso_v){ return *((T*)(&data)); }else{ return *(static_cast(data)); diff --git a/include/pocketpy/common.h b/include/pocketpy/common.h index 339884e0..bf91362d 100644 --- a/include/pocketpy/common.h +++ b/include/pocketpy/common.h @@ -129,9 +129,6 @@ struct Type { template inline constexpr bool is_pod_v = std::is_trivially_copyable_v && std::is_standard_layout_v; -template -inline constexpr bool is_sso_v = is_pod_v && sizeof(T) <= sizeof(void*); - #define PK_ALWAYS_PASS_BY_POINTER(T) \ T(const T&) = delete; \ T& operator=(const T&) = delete; \ diff --git a/include/pocketpy/linalg.h b/include/pocketpy/linalg.h index eb80bb53..fd4f250e 100644 --- a/include/pocketpy/linalg.h +++ b/include/pocketpy/linalg.h @@ -124,9 +124,9 @@ struct Mat3x3{ void add_module_linalg(VM* vm); static_assert(sizeof(Py_) <= 64); -static_assert(std::is_trivially_copyable::value); -static_assert(std::is_trivially_copyable::value); -static_assert(std::is_trivially_copyable::value); -static_assert(std::is_trivially_copyable::value); +static_assert(is_pod_v); +static_assert(is_pod_v); +static_assert(is_pod_v); +static_assert(is_pod_v); } // namespace pkpy \ No newline at end of file