signal_less.cpp 1.5 KB

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