signal_less.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <array>
  2. #include <type_traits>
  3. #include <gtest/gtest.h>
  4. #include <entt/entity/registry.hpp>
  5. #include <entt/entity/storage.hpp>
  6. struct SignalLess: testing::Test {
  7. enum my_entity : std::uint32_t {};
  8. template<typename>
  9. struct has_on_construct: std::false_type {};
  10. template<typename Type>
  11. requires requires { entt::storage_type_t<Type, my_entity>::on_construct; }
  12. struct has_on_construct<Type>: std::true_type {};
  13. template<typename Type>
  14. static constexpr auto has_on_construct_v = has_on_construct<Type>::value;
  15. };
  16. template<typename Type>
  17. struct entt::storage_type<Type, SignalLess::my_entity> {
  18. // no signal regardless of element type ...
  19. using type = basic_storage<Type, SignalLess::my_entity>;
  20. };
  21. template<>
  22. struct entt::storage_type<char, SignalLess::my_entity> {
  23. // ... unless it's char, because yes.
  24. using type = sigh_mixin<basic_storage<char, SignalLess::my_entity>>;
  25. };
  26. TEST_F(SignalLess, Example) {
  27. // invoking registry::on_construct<int> is a compile-time error
  28. ASSERT_FALSE((has_on_construct_v<int>));
  29. ASSERT_TRUE((has_on_construct_v<char>));
  30. entt::basic_registry<my_entity> registry;
  31. const std::array entity{registry.create()};
  32. // literally a test for storage_adapter_mixin
  33. registry.emplace<int>(entity[0], 0);
  34. registry.erase<int>(entity[0]);
  35. registry.insert<int>(entity.begin(), entity.end(), 3);
  36. registry.patch<int>(entity[0], [](auto &value) { value = 2; });
  37. ASSERT_EQ(registry.get<int>(entity[0]), 2);
  38. }