signal_less.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. struct SignalLess: testing::Test {
  7. enum entity : std::uint32_t {};
  8. template<typename, typename = void>
  9. struct has_on_construct: std::false_type {};
  10. template<typename Type>
  11. struct has_on_construct<Type, std::void_t<decltype(&entt::storage_type_t<Type, entity>::on_construct)>>: std::true_type {};
  12. template<typename Type>
  13. static constexpr auto has_on_construct_v = has_on_construct<Type>::value;
  14. };
  15. template<typename Type>
  16. struct entt::storage_type<Type, SignalLess::entity> {
  17. // no signal regardless of element type ...
  18. using type = basic_storage<Type, SignalLess::entity>;
  19. };
  20. template<>
  21. struct entt::storage_type<char, SignalLess::entity> {
  22. // ... unless it's char, because yes.
  23. using type = sigh_mixin<basic_storage<char, SignalLess::entity>>;
  24. };
  25. TEST_F(SignalLess, Example) {
  26. // invoking registry::on_construct<int> is a compile-time error
  27. ASSERT_FALSE((has_on_construct_v<int>));
  28. ASSERT_TRUE((has_on_construct_v<char>));
  29. entt::basic_registry<entity> 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>(entity.begin(), entity.end(), 3);
  35. registry.patch<int>(entity[0], [](auto &value) { value = 2; });
  36. ASSERT_EQ(registry.get<int>(entity[0]), 2);
  37. }