value_type.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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() = default;
  18. };
  19. template<typename Type>
  20. struct non_movable_mixin: Type {
  21. using Type::Type;
  22. non_movable_mixin(non_movable_mixin &&) = delete;
  23. non_movable_mixin(const non_movable_mixin &) = default;
  24. non_movable_mixin &operator=(non_movable_mixin &&) = delete;
  25. non_movable_mixin &operator=(const non_movable_mixin &) = default;
  26. };
  27. struct value_type {
  28. constexpr value_type() = default;
  29. constexpr value_type(int elem): value{elem} {}
  30. [[nodiscard]] constexpr bool operator==(const value_type &) const noexcept = default;
  31. [[nodiscard]] constexpr auto operator<=>(const value_type &) const noexcept = default;
  32. int value{};
  33. };
  34. } // namespace internal
  35. using pointer_stable = internal::pointer_stable_mixin<internal::value_type>;
  36. using non_trivially_destructible = internal::non_trivially_destructible_mixin<internal::value_type>;
  37. using pointer_stable_non_trivially_destructible = internal::pointer_stable_mixin<internal::non_trivially_destructible_mixin<internal::value_type>>;
  38. using non_movable = internal::non_movable_mixin<internal::value_type>;
  39. static_assert(std::is_trivially_destructible_v<test::pointer_stable>, "Not a trivially destructible type");
  40. static_assert(!std::is_trivially_destructible_v<test::non_trivially_destructible>, "Trivially destructible type");
  41. static_assert(!std::is_trivially_destructible_v<test::pointer_stable_non_trivially_destructible>, "Trivially destructible type");
  42. static_assert(!std::is_move_constructible_v<test::non_movable> && !std::is_move_assignable_v<test::non_movable>, "Movable type");
  43. } // namespace test
  44. #endif