Browse Source

feat: add `is_compact_layout_v` concept

master
Dnomd343 17 hours from now
parent
commit
0abf437ae1
  1. 4
      src/core/common_code/common_code.h
  2. 6
      src/core/group/group.h
  3. 4
      src/core/raw_code/raw_code.h
  4. 2
      src/core/short_code/short_code.h
  5. 8
      src/core/utils/utility.h

4
src/core/common_code/common_code.h

@ -63,8 +63,8 @@
#include <string>
#include <cstdint>
#include <optional>
#include <type_traits>
#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<CommonCode>);
static_assert(std::is_standard_layout_v<CommonCode>);
static_assert(std::is_trivially_copyable_v<CommonCode>);
static_assert(std::has_unique_object_representations_v<CommonCode>);
} // namespace klotski::codec

6
src/core/group/group.h

@ -245,9 +245,9 @@ private:
};
static_assert(sizeof(GroupUnion) == 1);
static_assert(is_compact_layout_v<GroupUnion>);
static_assert(std::is_standard_layout_v<GroupUnion>);
static_assert(std::is_trivially_copyable_v<GroupUnion>);
static_assert(std::has_unique_object_representations_v<GroupUnion>);
} // namespace klotski::group
@ -371,9 +371,9 @@ private:
};
static_assert(sizeof(Group) == 4);
static_assert(is_compact_layout_v<Group>);
static_assert(std::is_standard_layout_v<Group>);
static_assert(std::is_trivially_copyable_v<Group>);
static_assert(std::has_unique_object_representations_v<Group>);
} // namespace klotski::group
@ -432,9 +432,9 @@ private:
};
static_assert(sizeof(CaseInfo) == 8);
static_assert(is_compact_layout_v<CaseInfo>);
static_assert(std::is_standard_layout_v<CaseInfo>);
static_assert(std::is_trivially_copyable_v<CaseInfo>);
static_assert(std::has_unique_object_representations_v<CaseInfo>);
} // namespace klotski::group

4
src/core/raw_code/raw_code.h

@ -66,8 +66,8 @@
#include <string>
#include <cstdint>
#include <optional>
#include <type_traits>
#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<RawCode>);
static_assert(std::is_standard_layout_v<RawCode>);
static_assert(std::is_trivially_copyable_v<RawCode>);
static_assert(std::has_unique_object_representations_v<RawCode>);
} // namespace klotski::codec

2
src/core/short_code/short_code.h

@ -187,9 +187,9 @@ private:
};
static_assert(sizeof(ShortCode) == 4);
static_assert(is_compact_layout_v<ShortCode>);
static_assert(std::is_standard_layout_v<ShortCode>);
static_assert(std::is_trivially_copyable_v<ShortCode>);
static_assert(std::has_unique_object_representations_v<ShortCode>);
} // namespace klotski::codec

8
src/core/utils/utility.h

@ -6,6 +6,7 @@
#include <cstdint>
#include <numeric>
#include <functional>
#include <type_traits>
// ----------------------------------------------------------------------------------------- //
@ -62,6 +63,13 @@
namespace klotski {
template <typename T>
#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<T>;
#endif
/// Calculate the sum of an array of integers.
template <typename T, size_t N>
requires std::is_integral_v<T>

Loading…
Cancel
Save