blueloveTH 1 năm trước cách đây
mục cha
commit
f708fc4f98
3 tập tin đã thay đổi với 10 bổ sung10 xóa
  1. 6 3
      include/pocketpy/any.h
  2. 0 3
      include/pocketpy/common.h
  3. 4 4
      include/pocketpy/linalg.h

+ 6 - 3
include/pocketpy/any.h

@@ -5,6 +5,9 @@
 
 namespace pkpy {
 
+template<typename T>
+inline constexpr bool is_any_sso_v = is_pod_v<T> && sizeof(T) <= sizeof(void*);
+
 struct any{
     struct vtable{
         const std::type_index type;
@@ -13,7 +16,7 @@ struct any{
         template<typename T>
         inline static vtable* get(){
             static_assert(std::is_same_v<T, std::decay_t<T>>);
-            if constexpr (is_sso_v<T>){
+            if constexpr (is_any_sso_v<T>){
                 static vtable vt{ typeid(T), nullptr };
                 return &vt;
             }else{
@@ -35,7 +38,7 @@ struct any{
         using U = std::decay_t<T>;
         static_assert(!std::is_same_v<U, any>, "any(const any&) is deleted");
         static_assert(sizeof(U) == sizeof(T));
-        if constexpr (is_sso_v<U>){
+        if constexpr (is_any_sso_v<U>){
             memcpy(&data, &value, sizeof(U));
         }else{
             data = new U(std::forward<T>(value));
@@ -58,7 +61,7 @@ struct any{
     template<typename T>
     T& _cast() const noexcept{
         static_assert(std::is_same_v<T, std::decay_t<T>>);
-        if constexpr (is_sso_v<T>){
+        if constexpr (is_any_sso_v<T>){
             return *((T*)(&data));
         }else{
             return *(static_cast<T*>(data));

+ 0 - 3
include/pocketpy/common.h

@@ -129,9 +129,6 @@ struct Type {
 template<typename T>
 inline constexpr bool is_pod_v = std::is_trivially_copyable_v<T> && std::is_standard_layout_v<T>;
 
-template<typename T>
-inline constexpr bool is_sso_v = is_pod_v<T> && sizeof(T) <= sizeof(void*);
-
 #define PK_ALWAYS_PASS_BY_POINTER(T) \
 	T(const T&) = delete; \
 	T& operator=(const T&) = delete; \

+ 4 - 4
include/pocketpy/linalg.h

@@ -124,9 +124,9 @@ struct Mat3x3{
 void add_module_linalg(VM* vm);
 
 static_assert(sizeof(Py_<Mat3x3>) <= 64);
-static_assert(std::is_trivially_copyable<Vec2>::value);
-static_assert(std::is_trivially_copyable<Vec3>::value);
-static_assert(std::is_trivially_copyable<Vec4>::value);
-static_assert(std::is_trivially_copyable<Mat3x3>::value);
+static_assert(is_pod_v<Vec2>);
+static_assert(is_pod_v<Vec3>);
+static_assert(is_pod_v<Vec4>);
+static_assert(is_pod_v<Mat3x3>);
 
 }   // namespace pkpy