From 0abf437ae17c324f25e733acac1fac187243f26b Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 28 Dec 2024 09:32:06 +0800 Subject: [PATCH] feat: add `is_compact_layout_v` concept --- src/core/common_code/common_code.h | 4 ++-- src/core/group/group.h | 6 +++--- src/core/raw_code/raw_code.h | 4 ++-- src/core/short_code/short_code.h | 2 +- src/core/utils/utility.h | 8 ++++++++ 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/common_code/common_code.h b/src/core/common_code/common_code.h index cee3078..fda4e64 100644 --- a/src/core/common_code/common_code.h +++ b/src/core/common_code/common_code.h @@ -63,8 +63,8 @@ #include #include #include -#include +#include "utils/utility.h" #include "raw_code/raw_code_fwd.h" #include "short_code/short_code_fwd.h" @@ -194,9 +194,9 @@ private: }; static_assert(sizeof(CommonCode) == 8); +static_assert(is_compact_layout_v); static_assert(std::is_standard_layout_v); static_assert(std::is_trivially_copyable_v); -static_assert(std::has_unique_object_representations_v); } // namespace klotski::codec diff --git a/src/core/group/group.h b/src/core/group/group.h index 671ac84..b92fc9b 100644 --- a/src/core/group/group.h +++ b/src/core/group/group.h @@ -245,9 +245,9 @@ private: }; static_assert(sizeof(GroupUnion) == 1); +static_assert(is_compact_layout_v); static_assert(std::is_standard_layout_v); static_assert(std::is_trivially_copyable_v); -static_assert(std::has_unique_object_representations_v); } // namespace klotski::group @@ -371,9 +371,9 @@ private: }; static_assert(sizeof(Group) == 4); +static_assert(is_compact_layout_v); static_assert(std::is_standard_layout_v); static_assert(std::is_trivially_copyable_v); -static_assert(std::has_unique_object_representations_v); } // namespace klotski::group @@ -432,9 +432,9 @@ private: }; static_assert(sizeof(CaseInfo) == 8); +static_assert(is_compact_layout_v); static_assert(std::is_standard_layout_v); static_assert(std::is_trivially_copyable_v); -static_assert(std::has_unique_object_representations_v); } // namespace klotski::group diff --git a/src/core/raw_code/raw_code.h b/src/core/raw_code/raw_code.h index 0245bf6..0201e42 100644 --- a/src/core/raw_code/raw_code.h +++ b/src/core/raw_code/raw_code.h @@ -66,8 +66,8 @@ #include #include #include -#include +#include "utils/utility.h" #include "common_code/common_code_fwd.h" namespace klotski::codec { @@ -171,9 +171,9 @@ private: }; static_assert(sizeof(RawCode) == 8); +static_assert(is_compact_layout_v); static_assert(std::is_standard_layout_v); static_assert(std::is_trivially_copyable_v); -static_assert(std::has_unique_object_representations_v); } // namespace klotski::codec diff --git a/src/core/short_code/short_code.h b/src/core/short_code/short_code.h index 9c9b740..bf95ea4 100644 --- a/src/core/short_code/short_code.h +++ b/src/core/short_code/short_code.h @@ -187,9 +187,9 @@ private: }; static_assert(sizeof(ShortCode) == 4); +static_assert(is_compact_layout_v); static_assert(std::is_standard_layout_v); static_assert(std::is_trivially_copyable_v); -static_assert(std::has_unique_object_representations_v); } // namespace klotski::codec diff --git a/src/core/utils/utility.h b/src/core/utils/utility.h index e1ffa35..5938c32 100644 --- a/src/core/utils/utility.h +++ b/src/core/utils/utility.h @@ -6,6 +6,7 @@ #include #include #include +#include // ----------------------------------------------------------------------------------------- // @@ -62,6 +63,13 @@ namespace klotski { +template +#ifndef __cpp_lib_has_unique_object_representations +concept is_compact_layout_v = true; +#else +concept is_compact_layout_v = std::has_unique_object_representations_v; +#endif + /// Calculate the sum of an array of integers. template requires std::is_integral_v