value_type.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. namespace internal {
  7. template<typename Type>
  8. struct pointer_stable_mixin: Type {
  9. static constexpr auto in_place_delete = true;
  10. using Type::Type;
  11. using Type::operator=;
  12. };
  13. template<typename Type>
  14. struct non_trivially_destructible_mixin: Type {
  15. using Type::Type;
  16. using Type::operator=;
  17. virtual ~non_trivially_destructible_mixin() noexcept = default;
  18. };
  19. template<typename Type>
  20. struct non_comparable_mixin: Type {
  21. using Type::Type;
  22. using Type::operator=;
  23. bool operator==(const non_comparable_mixin &) const noexcept = delete;
  24. };
  25. template<typename Type>
  26. struct non_movable_mixin: Type {
  27. using Type::Type;
  28. non_movable_mixin(non_movable_mixin &&) noexcept = delete;
  29. non_movable_mixin(const non_movable_mixin &) noexcept = default;
  30. non_movable_mixin &operator=(non_movable_mixin &&) noexcept = delete;
  31. non_movable_mixin &operator=(const non_movable_mixin &) noexcept = default;
  32. };
  33. struct value_type {
  34. constexpr value_type() = default;
  35. constexpr value_type(int elem): value{elem} {}
  36. [[nodiscard]] constexpr bool operator==(const value_type &) const noexcept = default;
  37. [[nodiscard]] constexpr auto operator<=>(const value_type &) const noexcept = default;
  38. int value{};
  39. };
  40. } // namespace internal
  41. using pointer_stable = internal::pointer_stable_mixin<internal::value_type>;
  42. using non_trivially_destructible = internal::non_trivially_destructible_mixin<internal::value_type>;
  43. using pointer_stable_non_trivially_destructible = internal::pointer_stable_mixin<internal::non_trivially_destructible_mixin<internal::value_type>>;
  44. using non_comparable = internal::non_comparable_mixin<internal::value_type>;
  45. using non_movable = internal::non_movable_mixin<internal::value_type>;
  46. static_assert(std::is_trivially_destructible_v<test::pointer_stable>, "Not a trivially destructible type");
  47. static_assert(!std::is_trivially_destructible_v<test::non_trivially_destructible>, "Trivially destructible type");
  48. static_assert(!std::is_trivially_destructible_v<test::pointer_stable_non_trivially_destructible>, "Trivially destructible type");
  49. static_assert(!std::is_move_constructible_v<test::non_movable> && !std::is_move_assignable_v<test::non_movable>, "Movable type");
  50. } // namespace test
  51. #endif