signal_less.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. template<typename Type, typename Entity>
  7. struct entt::storage_type<Type, Entity> {
  8. // no signal regardless of element type ...
  9. using type = basic_storage<Type, Entity>;
  10. };
  11. template<typename Entity>
  12. struct entt::storage_type<char, Entity> {
  13. // ... unless it's char, because yes.
  14. using type = sigh_mixin<basic_storage<char, Entity>>;
  15. };
  16. template<typename, typename, typename = void>
  17. struct has_on_construct: std::false_type {};
  18. template<typename Entity, typename Type>
  19. struct has_on_construct<Entity, Type, std::void_t<decltype(&entt::storage_type_t<Type>::on_construct)>>: std::true_type {};
  20. template<typename Entity, typename Type>
  21. inline constexpr auto has_on_construct_v = has_on_construct<Entity, Type>::value;
  22. TEST(Example, SignalLess) {
  23. // invoking registry::on_construct<int> is a compile-time error
  24. ASSERT_FALSE((has_on_construct_v<entt::entity, int>));
  25. ASSERT_TRUE((has_on_construct_v<entt::entity, char>));
  26. entt::registry registry;
  27. const std::array entity{registry.create()};
  28. // literally a test for storage_adapter_mixin
  29. registry.emplace<int>(entity[0], 0);
  30. registry.erase<int>(entity[0]);
  31. registry.insert<int>(entity.begin(), entity.end(), 3);
  32. registry.patch<int>(entity[0], [](auto &value) { value = 2; });
  33. ASSERT_EQ(registry.get<int>(entity[0]), 2);
  34. }