value_type.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef ENTT_COMMON_VALUE_TYPE_H
  2. #define ENTT_COMMON_VALUE_TYPE_H
  3. #include <compare>
  4. #include <type_traits>
  5. namespace test {
  6. template<typename... Type>
  7. struct pointer_stable_mixin: Type... {
  8. static constexpr auto in_place_delete = true;
  9. [[nodiscard]] constexpr bool operator==(const pointer_stable_mixin &) const noexcept = default;
  10. [[nodiscard]] constexpr auto operator<=>(const pointer_stable_mixin &) const noexcept = default;
  11. };
  12. template<typename... Type>
  13. struct non_trivially_destructible_mixin: Type... {
  14. [[nodiscard]] constexpr bool operator==(const non_trivially_destructible_mixin &) const noexcept = default;
  15. [[nodiscard]] constexpr auto operator<=>(const non_trivially_destructible_mixin &) const noexcept = default;
  16. virtual ~non_trivially_destructible_mixin() = default;
  17. };
  18. template<typename... Type>
  19. struct value_type final: Type... {
  20. constexpr value_type() = default;
  21. constexpr value_type(int elem): value{elem} {}
  22. [[nodiscard]] constexpr bool operator==(const value_type &) const noexcept = default;
  23. [[nodiscard]] constexpr auto operator<=>(const value_type &) const noexcept = default;
  24. int value{};
  25. };
  26. using pointer_stable = value_type<pointer_stable_mixin<>>;
  27. using non_trivially_destructible = value_type<non_trivially_destructible_mixin<>>;
  28. using pointer_stable_non_trivially_destructible = value_type<pointer_stable_mixin<non_trivially_destructible_mixin<>>>;
  29. static_assert(std::is_trivially_destructible_v<test::pointer_stable>, "Not a trivially destructible type");
  30. static_assert(!std::is_trivially_destructible_v<test::non_trivially_destructible>, "Trivially destructible type");
  31. static_assert(!std::is_trivially_destructible_v<test::pointer_stable_non_trivially_destructible>, "Trivially destructible type");
  32. } // namespace test
  33. #endif