🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.5 KiB

  1. #include <iterator>
  2. #include <type_traits>
  3. #include <gtest/gtest.h>
  4. #include <entt/entity/entity.hpp>
  5. #include <entt/entity/registry.hpp>
  6. template<typename Entity, typename Type>
  7. struct entt::storage_traits<Entity, Type> {
  8. // no signal regardless of component type ...
  9. using storage_type = basic_storage<Entity, Type>;
  10. };
  11. template<typename Entity>
  12. struct entt::storage_traits<Entity, char> {
  13. // ... unless it's char, because yes.
  14. using storage_type = sigh_storage_mixin<basic_storage<Entity, char>>;
  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_traits<Entity, Type>::storage_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. static_assert(!has_on_construct_v<entt::entity, int>);
  25. static_assert(has_on_construct_v<entt::entity, char>);
  26. entt::registry registry;
  27. const entt::entity entity[1u]{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>(std::begin(entity), std::end(entity), 3);
  32. registry.patch<int>(entity[0], [](auto &value) { value = 42; });
  33. ASSERT_EQ(registry.get<int>(entity[0]), 42);
  34. }