signal_less.cpp 1.5 KB

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