signal_less.cpp 1.5 KB

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