value_type.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_default_constructible_mixin: Type {
  15. using Type::Type;
  16. using Type::operator=;
  17. non_default_constructible_mixin() = delete;
  18. };
  19. template<typename Type>
  20. struct non_trivially_destructible_mixin: Type {
  21. using Type::Type;
  22. using Type::operator=;
  23. virtual ~non_trivially_destructible_mixin() noexcept = default;
  24. };
  25. template<typename Type>
  26. struct non_comparable_mixin: Type {
  27. using Type::Type;
  28. using Type::operator=;
  29. bool operator==(const non_comparable_mixin &) const noexcept = delete;
  30. };
  31. template<typename Type>
  32. struct non_movable_mixin: Type {
  33. using Type::Type;
  34. non_movable_mixin(non_movable_mixin &&) noexcept = delete;
  35. non_movable_mixin(const non_movable_mixin &) noexcept = default;
  36. non_movable_mixin &operator=(non_movable_mixin &&) noexcept = delete;
  37. non_movable_mixin &operator=(const non_movable_mixin &) noexcept = default;
  38. };
  39. struct empty_type {};
  40. struct aggregate_type {
  41. [[nodiscard]] constexpr bool operator==(const aggregate_type &) const noexcept = default;
  42. [[nodiscard]] constexpr auto operator<=>(const aggregate_type &) const noexcept = default;
  43. int value{};
  44. };
  45. template<typename Type>
  46. struct value_type {
  47. constexpr value_type() = default;
  48. constexpr value_type(Type elem): value{elem} {}
  49. [[nodiscard]] constexpr bool operator==(const value_type &) const noexcept = default;
  50. [[nodiscard]] constexpr auto operator<=>(const value_type &) const noexcept = default;
  51. operator Type() const noexcept {
  52. return value;
  53. }
  54. Type value{};
  55. };
  56. } // namespace internal
  57. using pointer_stable = internal::pointer_stable_mixin<internal::value_type<int>>;
  58. using pointer_stable_non_trivially_destructible = internal::pointer_stable_mixin<internal::non_trivially_destructible_mixin<internal::value_type<int>>>;
  59. using non_default_constructible = internal::non_default_constructible_mixin<internal::value_type<int>>;
  60. using non_trivially_destructible = internal::non_trivially_destructible_mixin<internal::value_type<int>>;
  61. using non_comparable = internal::non_comparable_mixin<internal::empty_type>;
  62. using non_movable = internal::non_movable_mixin<internal::value_type<int>>;
  63. using boxed_int = internal::value_type<int>;
  64. using boxed_char = internal::value_type<char>;
  65. using empty = internal::empty_type;
  66. struct other_empty: internal::empty_type {};
  67. using aggregate = internal::aggregate_type;
  68. static_assert(std::is_trivially_destructible_v<pointer_stable>, "Not a trivially destructible type");
  69. static_assert(!std::is_trivially_destructible_v<non_trivially_destructible>, "Trivially destructible type");
  70. static_assert(!std::is_trivially_destructible_v<pointer_stable_non_trivially_destructible>, "Trivially destructible type");
  71. static_assert(!std::is_move_constructible_v<non_movable> && !std::is_move_assignable_v<non_movable>, "Movable type");
  72. static_assert(std::is_aggregate_v<aggregate>, "Not an aggregate type");
  73. } // namespace test
  74. #endif